local extension = Package("aaa_steam1")
extension.extensionName = "aaa_steam"

local U = require "packages/utility/utility"
local RUtil = require "packages/aaa_fenghou/utility/rfenghou_util"
local DIY = require "packages/diy_utility/diy_utility"

Fk:loadTranslationTable{
  ["steam"] = "蒸",
  ["steam2"] = "蒸",
  ["steam3"] = "蒸",
  ["aaa_steam1"] = "steam1",
}

local function AddWinAudio(general)
  local Win = fk.CreateActiveSkill{ name = general.name.."_win_audio" }
  Win.package = extension
  Fk:addSkill(Win)
end

local lixiu = General(extension, "steam__lixiu", "jin", 3, 4, General.Female)
local qingshi = fk.CreateTriggerSkill{
  name = "steam__qingshi",
  frequency = Skill.Compulsory,
  mute = true,
  events = {fk.TurnStart, fk.EventPhaseChanging, fk.DrawNCards, fk.EventPhaseStart, fk.EventPhaseProceeding},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.TurnStart then
        return #player.room:canMoveCardInBoard() > 0
      else
        local n = 0
        for _, p in ipairs(player.room.players) do
          n = n + p:getLostHp()
        end
        n = n // #player.room.players
        if event == fk.EventPhaseChanging then
          return data.to == Player.Judge and n >= 1
        elseif event == fk.DrawNCards then
          return data.n > 0 and n >= 2
        elseif event == fk.EventPhaseStart then
          return player.phase == Player.Play and n >= 3 and
            table.find(player.room.discard_pile, function (id)
              return Fk:getCardById(id).trueName == "slash"
            end)
        elseif event == fk.EventPhaseProceeding then
          return player.phase == Player.Discard and player:getHandcardNum() - player:getMaxCards() > 2 and n >= 4
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
      local targets = room:askForChooseToMoveCardInBoard(player, "#steam__qingshi-move", self.name, true)
      if #targets > 0 then
        player:broadcastSkillInvoke(self.name)
        room:notifySkillInvoked(player, self.name, "control")
        room:askForMoveCardInBoard(player, room:getPlayerById(targets[1]), room:getPlayerById(targets[2]), self.name)
      end
    elseif event == fk.EventPhaseChanging then
      player:broadcastSkillInvoke(self.name)
      room:notifySkillInvoked(player, self.name, "defensive")
      return true
    elseif event == fk.DrawNCards and room:askForSkillInvoke(player, self.name, nil, "#steam__qingshi-draw") then
      player:broadcastSkillInvoke(self.name)
      room:notifySkillInvoked(player, self.name, "drawcard")
      data.n = player:getHandcardNum()
    elseif event == fk.EventPhaseStart then
      local card = room:getCardsFromPileByRule("slash", 1, "discardPile")
      if #card > 0 then
        player:broadcastSkillInvoke(self.name)
        room:notifySkillInvoked(player, self.name, "drawcard")
        room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, true, player.id)
      end
    elseif event == fk.EventPhaseProceeding then
      player:broadcastSkillInvoke(self.name)
      room:notifySkillInvoked(player, self.name, "defensive")
      room:askForDiscard(player, 2, 2, false, "phase_discard", false)
      player._phase_end = true
    end
  end,
}
lixiu:addSkill(qingshi)
Fk:loadTranslationTable{
  ["steam__lixiu"] = "李秀",
  ["#steam__lixiu"] = "明惠耀林",
  ["illustrator:steam__lixiu"] = "哥达耀",
  ["designer:steam__lixiu"] = "志文",
  ["cv:steam__lixiu"] = "桃妮儿",

  ["steam__qingshi"] = "情势",
  [":steam__qingshi"] = "锁定技，根据所有角色（包括已死亡角色）已损失体力值的平均值，你获得效果：<br>"..
  "不小于0点：回合开始时，你可以移动场上一张牌。<br>"..
  "不小于1点：你跳过判定阶段。<br>"..
  "不小于2点：摸牌阶段，你可以改为摸手牌数的牌。<br>"..
  "不小于3点：出牌阶段开始时，你从弃牌堆获得一张【杀】。<br>"..
  "不小于4点：弃牌阶段，若你的手牌数减手牌上限大于2，你改为弃置两张牌。",
  ["#steam__qingshi-move"] = "情势：你可以移动场上一张牌",
  ["#steam__qingshi-draw"] = "情势：是否改为摸手牌数的牌？",

  ["$steam__qingshi1"] = "决胜料敌，情势既得，断在不疑。",
  ["$steam__qingshi2"] = "勇而轻死、智则心怯，智勇并济者，方为大将。",
  ["$steam__qingshi3"] = "行营面面、帐门深深，出得沙场又安归？",
  ["~steam__lixiu"] = "父死女继，妻死夫继，誓扫蛮夷！",
}

local zhaoqu = General(extension, "steam__zhaoqu", "wei", 4)

local steam__chixiao = fk.CreateTriggerSkill{
  name = "steam__chixiao",
  frequency = Skill.Compulsory,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and not player:isKongcheng() then
      return #DIY.GetShownCards(player) < (player:getHandcardNum() / 2) and (player:getHandcardNum() % 2 == 0)
    end
  end,
  on_use = function(self, event, target, player, data)
    local num = player:getHandcardNum() // 2
    local cards = player.room:askForCard(player, num, num, false, self.name, false, nil, "#steam__chixiao-card")
    local shown = DIY.GetShownCards(player)
    local hidden = table.filter(cards, function (id)
      return not table.contains(shown, id)
    end)
    DIY.HideCards(player, shown)
    DIY.ShowCards(player, hidden)
  end,
}

local steam__chixiao_maxcards = fk.CreateMaxCardsSkill{
  name = "#steam__chixiao_maxcards",
  exclude_from = function(self, player, card)
    if player:hasSkill(steam__chixiao) then
      return card:getMark("@@ShownCards-inhand") == 0
    end
  end,
}
steam__chixiao:addRelatedSkill(steam__chixiao_maxcards)

zhaoqu:addSkill(steam__chixiao)

local steam__henge = fk.CreateTriggerSkill{
  name = "steam__henge",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.card then
      local useEvent = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      if useEvent then
        local use = useEvent.data[1]
        return use.from == player.id and data.card == use.card and use.extra_data and use.extra_data.steam__hengeInfo
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local useEvent = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
    if useEvent then
      local use = useEvent.data[1]
      if use.extra_data.steam__hengeInfo == "hidden" then
        player:broadcastSkillInvoke(self.name, 1)
        room:notifySkillInvoked(player, self.name, "negative")
        local shown = DIY.GetShownCards(player)
        if #shown > 0 then
          local num = math.ceil(#shown / 2)
          room:askForDiscard(player, num, num, false, self.name, false, tostring(Exppattern{ id = shown }))
        end
      else
        player:broadcastSkillInvoke(self.name, 2)
        room:notifySkillInvoked(player, self.name, "drawcard")
        local hidden = table.filter(player:getCardIds("h"), function (id)
          return Fk:getCardById(id):getMark("@@ShownCards-inhand") == 0
        end)
        local num = math.floor(#hidden / 2)
        if num > 0 then
          player:drawCards(num, self.name)
        end
      end
    end
  end,

  refresh_events = {fk.PreCardUse},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(self, true)
  end,
  on_refresh = function (self, event, target, player, data)
    data.extra_data = data.extra_data or {}
    if data.card:getMark("@@ShownCards-inhand") > 0 then
      data.extra_data.steam__hengeInfo = "shown"
    else
      data.extra_data.steam__hengeInfo = "hidden"
    end
  end,
}
zhaoqu:addSkill(steam__henge)

Fk:loadTranslationTable{
  ["steam__zhaoqu"] = "赵衢",
  ["#steam__zhaoqu"] = "",
  ["designer:steam__zhaoqu"] = "半城",
  ["illustrator:steam__zhaoqu"] = "2B铅笔",

  ["steam__chixiao"] = "鸱鸮",
  [":steam__chixiao"] = "锁定技，你使用牌后，若明置牌数小于暗置牌数，且手牌数为偶数，你将一半手牌翻面；你的暗置牌不计入手牌上限。",
  ["#steam__chixiao-card"] = "鸱鸮：请选择半数手牌，将它们翻面",

  ["steam__henge"] = "衡扼",
  [":steam__henge"] = "锁定技，你使用暗置牌造成伤害后，弃置半数取上张明置牌；你使用明置牌造成伤害后，摸暗置牌的半数取下张牌。",
}

local mateng = General(extension, "steam__mateng", "qun", 4)
local xiongdang = fk.CreateActiveSkill{
  name = "steam__xiongdang",
  anim_type = "control",
  card_num = 0,
  min_target_num = 1,
  prompt = "#steam__xiongdang",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = Util.TrueFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:drawCards(#effect.tos, self.name)
    if player.dead or player:isKongcheng() then return end
    local cards = room:askForCard(player, #effect.tos, #effect.tos, false, self.name, false, nil,
      "#steam__xiongdang-show:::"..#effect.tos)
    player:showCards(cards)
    cards = table.filter(cards, function (id)
      return table.contains(player:getCardIds("h"), id)
    end)
    room:sortPlayersByAction(effect.tos)
    local targets = table.map(effect.tos, Util.Id2PlayerMapper)
    targets = table.filter(targets, function (p)
      return not p.dead
    end)
    while #targets > 0 and #cards > 0 and not player.dead do
      local to = targets[1]
      local use = U.askForUseRealCard(room, to, cards, nil, self.name,
      "#steam__xiongdang-use", {
        bypass_times = true,
        extraUse = true,
        expand_pile = to ~= player and cards or {},
      }, false, false)
      if use then
        table.removeOne(cards, use.card.id)
      else
        break
      end
      cards = table.filter(cards, function (id)
        return table.contains(player:getCardIds("h"), id)
      end)
      table.remove(targets, 1)
      table.insert(targets, to)
      targets = table.filter(targets, function (p)
        return not p.dead
      end)
    end
    cards = table.filter(cards, function (id)
      return table.contains(player:getCardIds("h"), id)
    end)
    if #cards > 0 then
      room:throwCard(cards, self.name, player, player)
    end
  end,
}
local beikou = fk.CreateTriggerSkill{
  name = "steam__beikou$",
  anim_type = "support",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    local cards = {}
    for _, move in ipairs(data) do
      if move.from == player.id and move.moveReason == fk.ReasonDiscard and move.toArea == Card.DiscardPile then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
            table.insertIfNeed(cards, info.cardId)
          end
        end
      end
    end
    cards = table.filter(cards, function(id) return player.room:getCardArea(id) == Card.DiscardPile end)
    cards = U.moveCardsHoldingAreaCheck(player.room, cards)
    if #cards > 0 then
      self.cost_data = {cards = cards}
      return true
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local _, dat = room:askForUseActiveSkill(player, "steam__beikou_active", "#steam__beikou-give",
    true, {expand_pile = self.cost_data.cards})
    if dat then
      self.cost_data = {tos = dat.targets, cards = dat.cards}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:obtainCard(self.cost_data.tos[1], self.cost_data.cards, true, fk.ReasonGive, player.id, self.name)
  end,
}
local beikou_active = fk.CreateActiveSkill{
  name = "steam__beikou_active",
  min_card_num = 1,
  target_num = 1,
  card_filter = function(self, to_select, selected)
    return type(self.expand_pile) == "table" and table.contains(self.expand_pile, to_select)
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    local to = Fk:currentRoom():getPlayerById(to_select)
    if #selected == 0 and Self.id ~= to_select then
      if to.kingdom ~= "qun" then
        return #selected_cards == 1
      else
        return #selected_cards > 0
      end
    end
  end,
}
Fk:addSkill(beikou_active)
mateng:addSkill(xiongdang)
mateng:addSkill("mashu")
mateng:addSkill(beikou)
Fk:loadTranslationTable{
  ["steam__mateng"] = "马腾",
  ["#steam__mateng"] = "驰骋西陲",
  ["illustrator:steam__mateng"] = "君桓文化",
  ["designer:steam__mateng"] = "胖即是胖",

  ["steam__xiongdang"] = "雄荡",
  [":steam__xiongdang"] = "出牌阶段限一次，你可以选择任意名角色，然后你摸等量张牌并展示等量张手牌；若如此做，这些角色依次使用一张因此展示的牌"..
  "直到无法使用，然后你弃置剩余的牌。",
  ["steam__beikou"] = "备寇",
  [":steam__beikou"] = "主公技，当你因弃置失去牌后，你可以将其中一张牌交给一名其他角色，或将其中任意张牌交给一名其他群势力角色。",
  ["#steam__xiongdang"] = "雄荡：选择任意名角色，你摸等量牌并展示等量牌，令这些角色依次使用其中一张",
  ["#steam__xiongdang-use"] = "雄荡：请使用其中一张牌",
  ["#steam__xiongdang-show"] = "雄荡：请展示%arg张牌",
  ["#steam__beikou-give"] = "备寇：你可将其中一张牌交给一名其他角色/任意张牌交给一名其他群势力角色",
  ["steam__beikou_active"] = "备寇分牌",

  ["$steam__xiongdang1"] = "弟兄们，我们的机会来了！",
  ["$steam__xiongdang2"] = "此时不战，更待何时！",
  ["$steam__beikou1"] = "集众人之力，成群雄霸业！",
  ["$steam__beikou2"] = "将士们，随我起誓！",["~steam__mateng"] = "逆子无谋，祸及全族。",
}

local godzhanghe = General(extension, "steam__godzhanghe", "god", 4)
for loop = 0, 50, 1 do  --50个应该够用
  local zhenmang = fk.CreateTriggerSkill{
    name = loop == 0 and "steam__zhenmang" or "steam"..loop.."__zhenmang",
    mute = true,
    frequency = Skill.Wake,
    events = {fk.TurnEnd},
    can_trigger = function(self, event, target, player, data)
      return player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and
        player.hp > 0 and player:getMark(self.name.."-turn") == 0  --防止因此获得技能时触发
    end,
    can_wake = function(self, event, target, player, data)
      return #player.room.logic:getActualDamageEvents(1, function (e)
        return e.data[1].damageType ~= fk.NormalDamage
      end, Player.HistoryTurn) > 0 or
      #player.room.logic:getEventsOfScope(GameEvent.Dying, 1, Util.TrueFunc,
        Player.HistoryTurn) > 0
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      player:broadcastSkillInvoke("steam__zhenmang")
      room:notifySkillInvoked(player, "steam__zhenmang", "special")
      local all_choices, choices = {}, {}
      for i = 1, 2, 1 do
        table.insert(all_choices, "steam__zhenmang_choice"..i)
        if player.hp >= i then
          table.insert(choices, "steam__zhenmang_choice"..i)
        end
      end
      if #choices == 0 then return end
      local choice = room:askForChoice(player, choices, "steam__zhenmang", nil, false, all_choices)
      if choice == "steam__zhenmang_choice1" then
        for i = 1, 50, 1 do
          local name = "steam"..i.."__xuncang"
          if not player:hasSkill(name, true) then
            player:setSkillUseHistory(name, 0, Player.HistoryGame)
            room:handleAddLoseSkills(player, name, nil, true, false)
            break
          end
        end
      elseif choice == "steam__zhenmang_choice2" then
        local skills = {}
        for i = 1, 50, 1 do
          local name = "steam"..i.."__zhenmang"
          if not player:hasSkill(name, true) then
            player:setSkillUseHistory(name, 0, Player.HistoryGame)
            room:setPlayerMark(player, name.."-turn", 1)
            table.insert(skills, name)
          end
          if #skills == 2 then break end
        end
        room:handleAddLoseSkills(player, skills, nil, true, false)
      --elseif choice == "steam__zhenmang_choice3" then
        --player:drawCards(3, "steam__zhenmang")
      end
    end,
  }
  if loop > 0 then
    Fk:addSkill(zhenmang)
  else
    godzhanghe:addSkill(zhenmang)
  end
  Fk:loadTranslationTable{
    ["steam"..loop.."__zhenmang"] = "震莽",
    [":steam"..loop.."__zhenmang"] = "觉醒技，进行过属性伤害或濒死结算的回合结束时，你选择体力值不小于序号的一项："..
    "1.获得一个〖巽苍〗；2.获得两个〖震莽〗。",
  }

  local xuncang = fk.CreateActiveSkill{
    name = loop == 0 and "steam__xuncang" or "steam"..loop.."__xuncang",
    mute = true,
    frequency = Skill.Limited,
    prompt = function ()
      if Self:getMark("steam__xuncang-phase") == 0 then
        return "#steam__xuncang-any"
      else
        return "#steam__xuncang:::"..(Self:getMark("steam__xuncang-phase") - 1)
      end
    end,
    min_card_num = 1,
    max_card_num = function ()
      if Self:getMark("steam__xuncang-phase") == 0 then
        return 999
      else
        return Self:getMark("steam__xuncang-phase") - 1
      end
    end,
    target_num = 1,
    times = function (self)
      return 1 - Self:usedSkillTimes(self.name, Player.HistoryGame)
    end,
    can_use = function(self, player)
      return player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and Self:getMark("steam__xuncang-phase") ~= 1
    end,
    card_filter = function(self, to_select, selected)
      return (Self:getMark("steam__xuncang-phase") == 0 or #selected < Self:getMark("steam__xuncang-phase") - 1) and
        not Self:prohibitDiscard(to_select)
    end,
    target_filter = function(self, to_select, selected, selected_cards)
      return #selected == 0
    end,
    on_use = function(self, room, effect)
      local player = room:getPlayerById(effect.from)
      local target = room:getPlayerById(effect.tos[1])
      player:broadcastSkillInvoke("steam__xuncang")
      room:notifySkillInvoked(player, "steam__xuncang", "offensive")
      room:setPlayerMark(player, "steam__xuncang-phase", #effect.cards)
      room:throwCard(effect.cards, self.name, player)
      if not target.dead then
        room:damage{
          from = player,
          to = target,
          damage = 1,
          damageType = fk.ThunderDamage,
          skillName = self.name,
        }
      end
    end,
  }
  if loop > 0 then
    Fk:addSkill(xuncang)
  else
    godzhanghe:addRelatedSkill(xuncang)
  end
  Fk:loadTranslationTable{
    ["steam"..loop.."__xuncang"] = "巽苍",
    [":steam"..loop.."__xuncang"] = "限定技，出牌阶段，你可以弃置至多X张牌（X本阶段上次弃置数-1），对一名角色造成1点雷电伤害。",
  }
end


local qiongyi = fk.CreateActiveSkill{
  name = "steam__qiongyi",
  card_num = 0,
  target_num = 0,
  prompt = function ()
    return "#steam__qiongyi:::"..Self:getMark("steam__qiongyi_times")
  end,
  card_filter = Util.FalseFunc,
  can_use = function(self, player)
    return #table.filter(player.player_skills, function (s)
      return s:isPlayerSkill(player) and s.visible
    end) >= player:getMark("steam__qiongyi_times")
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local skills = table.map(table.filter(player.player_skills, function (s)
      return s:isPlayerSkill(player) and s.visible
    end), Util.NameMapper)
    -- 为了避免删除未发动的技能，故做一下区分
    local skillToStr = function (list)
      return table.map(list, function (s)
        local skill = Fk.skills[s]
        if (skill.frequency == Skill.Limited or skill.frequency == Skill.Wake) and player:usedSkillTimes(s, Player.HistoryGame) > 0 then
          s = "SteamSkillInvoked:::"..s
        end
        return s
      end)
    end
    local returnSkill = function (list)
      return table.map(list, function (s)
        if s:startsWith("SteamSkillInvoked") then
          s = s:split(":::")[2]
        end
        return s
      end)
    end
    skills = skillToStr(skills)
    local min = player:getMark("steam__qiongyi_times")
    local tolose = {}
    if #skills <= min then
      tolose = table.simpleClone(skills)
    else
      tolose = room:askForChoices(player, skills, min, 999, self.name, "#steam__qiongyi-lose:::"..min, false)
    end
    tolose = returnSkill(tolose)
    room:setPlayerMark(player, "steam__qiongyi_times", #tolose + 1)
    if #tolose > 0 then
      room:handleAddLoseSkills(player, "-"..table.concat(tolose, "|-"))
    end
    if player.dead then return end
    room:changeMaxHp(player, 1)
    if player.dead then return end
    skills = table.map(table.filter(player.player_skills, function (s)
      return s:isPlayerSkill(player) and s.visible
    end), Util.NameMapper)
    skills = skillToStr(skills)
    if #skills > 0 then
      tolose = room:askForChoices(player, skills, 1, 1, self.name, "#steam__qiongyi-losetorecover", true)
      if #tolose > 0 then
        tolose = returnSkill(tolose)
        room:handleAddLoseSkills(player, "-"..tolose[1])
        room:recover { num = 1, skillName = self.name, who = player, recoverBy = player }
      end
    end
  end,
}

godzhanghe:addSkill(qiongyi)

--[[
local qiongyi = fk.CreateViewAsSkill{
  name = "steam__qiongyi",
  anim_type = "special",
  pattern = ".",
  prompt = function (self)
    if self.interaction.data then
      local card = Fk:cloneCard(self.interaction.data)
      if card.type == Card.TypeBasic then
        return "#steam__qiongyi-basic:::"..Self:getMark("@steam__qiongyi")[1]
      else
        return "#steam__qiongyi-trick:::"..Self:getMark("@steam__qiongyi")[2]
      end
    end
  end,
  interaction = function(self)
    local all_names = U.getAllCardNames("b")
    if #table.filter(Self.player_skills, function (s)
      return s:isPlayerSkill(Self) and s.visible
    end) >= Self:getMark("@steam__qiongyi")[2] then
      table.insertTable(all_names, U.getAllCardNames("t"))
    end
    local names = U.getViewAsCardNames(Self, self.name, all_names, {}, Self:getTableMark("@$steam__qiongyi"))
    if #names > 0 then
      return U.CardNameBox { choices = names, all_choices = all_names }
    end
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    if not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    room:addTableMark(player, "@$steam__qiongyi", use.card.trueName)
    local mark = player:getMark("@steam__qiongyi")
    local n = mark[1]
    if use.card:isCommonTrick() then
      n = mark[2]
    end
    if n > 0 then
      local skill_names = table.map(table.filter(player.player_skills, function (s)
        return s:isPlayerSkill(player) and s.visible
      end), function (s)
        return s.name
      end)
      local mapper = table.map(skill_names, function (name)
        if (name:startsWith("steam__zhenmang") or name:startsWith("steam__xuncang")) and
          player:usedSkillTimes(name, Player.HistoryGame) > 0 then
          return "√"
        else
          return ""
        end
      end)
      local choices = {}
      for i = 1, #skill_names, 1 do
        table.insert(choices, Util.TranslateMapper(skill_names[i])..mapper[i])
      end
      local choice = room:askForChoices(player, choices, n, n, self.name, "#steam__qiongyi-lose:::"..n, false)
      local skills = {}
      for _, c in ipairs(choice) do
        table.insert(skills, skill_names[table.indexOf(choices, c)])
      end
      room:handleAddLoseSkills(player, "-"..table.concat(skills, "|-"), nil, true, false)
    end
    for i = 1, 3, 1 do
      mark[i] = mark[i] + 1
    end
    room:setPlayerMark(player, "@steam__qiongyi", mark)
  end,
  enabled_at_play = function(self, player)
    return player:getMark("@steam__qiongyi") ~= 0 and
      #table.filter(player.player_skills, function (s)
        return s:isPlayerSkill(player) and s.visible
      end) >= player:getMark("@steam__qiongyi")[1]
  end,
  enabled_at_response = function(self, player, response)
    if Fk.currentResponsePattern == "nullification" then
      if table.contains(Self:getTableMark("@$steam__qiongyi"), "nullification") then return false end
    end
    return not response and player:getMark("@steam__qiongyi") ~= 0 and
      #table.filter(player.player_skills, function (s)
        return s:isPlayerSkill(player) and s.visible
      end) >= player:getMark("@steam__qiongyi")[1]
  end,
}
local qiongyi_trigger = fk.CreateTriggerSkill{
  name = "#steam__qiongyi_trigger",

  refresh_events = {fk.EventAcquireSkill, fk.EventLoseSkill},
  can_refresh = function(self, event, target, player, data)
    return target == player and data == qiongyi
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventAcquireSkill then
      room:setPlayerMark(player, "@steam__qiongyi", {0, 1, 2})
      room:handleAddLoseSkills(player, "steam__qiongyi_active&", nil, false, true)
    else
      room:setPlayerMark(player, "@steam__qiongyi", 0)
      room:setPlayerMark(player, "@$steam__qiongyi", 0)
      room:handleAddLoseSkills(player, "-steam__qiongyi_active&", nil, false, true)
    end
  end,
}
local qiongyi_active = fk.CreateActiveSkill{
  name = "steam__qiongyi_active&",
  anim_type = "support",
  card_num = 0,
  target_num = 0,
  prompt = function (self)
    return "#steam__qiongyi_active&:::"..Self:getMark("@steam__qiongyi")[3]
  end,
  can_use = function (self, player)
    return player:hasSkill(qiongyi) and player:getMark("@steam__qiongyi") ~= 0 and
      #table.filter(player.player_skills, function (s)
        return s:isPlayerSkill(player) and s.visible
      end) >= player:getMark("@steam__qiongyi")[3]
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:broadcastSkillInvoke("steam__qiongyi")
    local skill_names = table.map(table.filter(player.player_skills, function (s)
      return s:isPlayerSkill(player) and s.visible
    end), function (s)
      return s.name
    end)
    local mapper = table.map(skill_names, function (name)
      if (name:startsWith("steam__zhenmang") or name:startsWith("steam__xuncang")) and
        player:usedSkillTimes(name, Player.HistoryGame) > 0 then
        return "√"
      else
        return ""
      end
    end)
    local choices = {}
    for i = 1, #skill_names, 1 do
      table.insert(choices, Util.TranslateMapper(skill_names[i])..mapper[i])
    end
    local n = player:getMark("@steam__qiongyi")[3]
    local choice = room:askForChoices(player, choices, n, n, self.name, "#steam__qiongyi-lose:::"..n, false)
    local skills = {}
    for _, c in ipairs(choice) do
      table.insert(skills, skill_names[table.indexOf(choices, c)])
    end
    room:handleAddLoseSkills(player, "-"..table.concat(skills, "|-"), nil, true, false)
    room:setPlayerMark(player, "@steam__qiongyi", {0, 1, 2})
    room:setPlayerMark(player, "@$steam__qiongyi", 0)
    room:handleAddLoseSkills(player, "-"..table.concat(choice, "|-"), nil, true, false)
  end,
}
qiongyi:addRelatedSkill(qiongyi_trigger)
Fk:addSkill(qiongyi_active)
--]]
Fk:loadTranslationTable{
  ["steam__godzhanghe"] = "神张郃",
  ["#steam__godzhanghe"] = "不坠青云",
  ["designer:steam__godzhanghe"] = "末页",
  ["illustrator:steam__godzhanghe"] = "歪真人",
  ["cv:steam__godzhanghe"] = "末页",

  ["steam__zhenmang"] = "震莽",
  [":steam__zhenmang"] = "觉醒技，进行过属性伤害或濒死结算的回合结束时，你选择体力值不小于序号的一项：1.获得一个〖巽苍〗；"..
  "2.获得两个〖震莽〗。",
  ["steam__zhenmang_choice1"] = "获得一个〖巽苍〗",
  ["steam__zhenmang_choice2"] = "获得两个〖震莽〗",
  ["steam__zhenmang_choice3"] = "摸三张牌",

  ["steam__qiongyi"] = "穹异",
  [":steam__qiongyi"] = "出牌阶段，你可以失去任意个技能（至少0个，须比上一次多），加1点体力上限，你可以再失去一个以回复1点体力。",
  ["#steam__qiongyi"] = "穹异：失去至少%arg个技能，加1点体力上限",
  ["SteamSkillInvoked"] = "%arg(已发动)",
  ["#steam__qiongyi-lose"] = "穹异：请失去至少 %arg 个技能",
  ["#steam__qiongyi-losetorecover"] = "穹异：你可以再失去一个技能以回复1点体力",

  --[":steam__qiongyi"] = "你可以失去『0』/『1』个技能，视为使用一张未以此法使用过的基本牌/普通锦囊牌，令本技能的所有数字加一；出牌阶段，你可以失去『2』个技能，重置本技能的数字和记录。",
  --["#steam__qiongyi-basic"] = "穹异：你可以失去%arg个技能，视为使用一张基本牌！",
  --["#steam__qiongyi-trick"] = "穹异：你可以失去%arg个技能，视为使用一张普通锦囊牌！",
  --["#steam__qiongyi-lose"] = "穹异：请失去%arg个技能（“√”表示该技能已发动过）",
  --["steam__qiongyi_active&"] = "穹异[复原]",
  --[":steam__qiongyi_active&"] = "出牌阶段，你可以失去『2』个技能，重置“穹异”的数字和记录。",
  --["#steam__qiongyi_active&"] = "穹异：你可以失去%arg个技能，重置“穹异”的数字和记录！",
  --["@steam__qiongyi"] = "穹异",
  --["@$steam__qiongyi"] = "穹异",

  ["steam__xuncang"] = "巽苍",
  [":steam__xuncang"] = "限定技，出牌阶段，你可以弃置至多X张牌（X本阶段上次弃置数-1），对一名角色造成1点雷电伤害。",
  ["#steam__xuncang-any"] = "巽苍：你可以弃置任意张牌，对一名角色造成1点雷电伤害",
  ["#steam__xuncang"] = "巽苍：你可以弃置至多%arg张牌，对一名角色造成1点雷电伤害",

  ["$steam__zhenmang1"] = "授我斧钺，锡我彤弓，伐谋为兵，克胜群丑。",
  ["$steam__zhenmang2"] = "按剑则日中见斗，挥戈而曜灵再晡。",
  ["$steam__qiongyi1"] = "悬六合之休咎，着六军之成败。",
  ["$steam__qiongyi2"] = "玄穹彼苍，悉称上天；列缺飞廉，皆兆大横！",
  ["$steam__xuncang1"] = "挥云出塞、乘月渡河，旌旗指敌，荡寇清雠！",
  ["$steam__xuncang2"] = "苍雷注地飞紫星，龙子扰烟呼百灵。",
  ["~steam__godzhanghe"] = "授之者天，成之者运，岂徒人事？",
}

local thutmose = General(extension, "steam__thutmose_third", "west", 4)
local zaizhu = fk.CreateTriggerSkill{
  name = "steam__zaizhu",
  anim_type = "control",
  events = {fk.CardUsing},
  frequency = Skill.Compulsory,
  can_trigger = function (self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      local current = player.room.logic:getCurrentEvent()
      local last = player.room.logic:getEventsByRule(GameEvent.UseCard, 1, function (e)
        return e.id < current.id
      end, 1)[1]
      if last and last.data[1].from ~= player.id then
        local num = Fk:translate(data.card.trueName, "zh_CN"):len() + Fk:translate(last.data[1].card.trueName, "zh_CN"):len()
        local minus = math.abs(Fk:translate(data.card.trueName, "zh_CN"):len() - Fk:translate(last.data[1].card.trueName, "zh_CN"):len())
        if num ~= player:getHandcardNum() then
          self.cost_data = {num = num, minus = minus}
          return true
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local num = player:getHandcardNum() - self.cost_data.num
    if num > 0 then
      local cards = room:askForDiscard(player, num, num, false, self.name, true, ".|.|.|hand",
      "#steam__zaizhu-cost:::"..num..":"..(self.cost_data.minus), true)
      if #cards > 0 then
        self.cost_data.cards = cards
        return true
      end
    else
      return room:askForSkillInvoke(player, self.name, nil, "#steam__zaizhu-draw:::"..(-num))
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if not self.cost_data.cards then
      player:drawCards(self.cost_data.num - player:getHandcardNum(), self.name)
      return
    end
    room:throwCard(self.cost_data.cards, self.name, player, player)
    if player.dead or #self.cost_data.cards < 2 then return end
    local minus = self.cost_data.minus
    local targets = room:getOtherPlayers(player, false)
    local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1,
    "#steam__zaizhu-choose:::"..minus, self.name, true)
    if #tos > 0 then
      local to = room:getPlayerById(tos[1])
      local num = to:getHandcardNum() - minus
      if num > 0 then
        room:askForDiscard(to, num, num, false, self.name, false)
      elseif num < 0 then
        to:drawCards(-num, self.name)
      end
    end
  end,
}
thutmose:addSkill(zaizhu)

local lvzheng = fk.CreateTriggerSkill{
  name = "steam__lvzheng$",
  events = {fk.EventPhaseStart},
  anim_type = "control",
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(self) then
      if player.phase == Player.Start and #player:getCardIds("j") > 0 then
        return table.find(player.room.alive_players, function (p)
          return p ~= player and #p:getCardIds("j") > 0 and p.kingdom == "west"
        end)
      elseif player.phase == Player.Finish and #player:getCardIds("e") > 0 then
        return table.find(player.room.alive_players, function (p)
          return p ~= player and #p:getCardIds("e") > 0 and p.kingdom ~= "west"
        end)
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local targets = table.filter(player.room:getOtherPlayers(player, false), function (p)
      if player.phase == Player.Start then
        return #p:getCardIds("j") > 0 and p.kingdom == "west"
      else
        return #p:getCardIds("e") > 0 and p.kingdom ~= "west"
      end
    end)
    if #targets == 0 then return false end
    local tos = player.room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1,
    player.phase == Player.Start and "#steam__lvzheng-judge" or "#steam__lvzheng-equip", self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    local area = player.phase == Player.Start and "j" or "e"
    for _, p in ipairs({player, to}) do
      if #p:getCardIds(area) > 0 then
        local cid = room:askForCardChosen(player, p, area, self.name)
        room:throwCard(cid, self.name, p, player)
      end
    end
  end,
}
thutmose:addSkill(lvzheng)
Fk:loadTranslationTable{
  ["steam__thutmose_third"] = "图特摩斯三世",
  ["#steam__thutmose_third"] = "荣日重光",
  ["designer:steam__thutmose_third"] = "杨林",
  ["illustrator:steam__thutmose_third"] = "",

  ["steam__zaizhu"] = "再铸",
  [":steam__zaizhu"] = "连击技（其他角色使用牌+你使用牌），你可将你的手牌张数调整至这两张牌牌名字数之和；若你因此弃置至少两张牌，你可令一名其他角色调整手牌数至这两张牌牌名字数之差。",
  ["#steam__zaizhu-draw"] = "再铸：你可以摸 %arg 张牌",
  ["#steam__zaizhu-cost"] = "再铸：你可以弃置 %arg 张手牌，若至少弃2张，可将一名其他角色手牌调整至%arg2张",
  ["#steam__zaizhu-choose"] = "再铸：你可令一名其他角色调整手牌至%arg",
  ["steam__zaizhu_tip"] = "再铸",

  ["steam__lvzheng"] = "屡征",
  [":steam__lvzheng"] = "主公技，准备阶段/结束阶段，你可弃置你和一名其他西势力角色判定区/其他非西势力角色装备区的各一张牌。",
  ["#steam__lvzheng-judge"] = "屡征：你可弃置你和一名其他西势力角色判定区各一张牌",
  ["#steam__lvzheng-equip"] = "屡征：你可弃置你和一名其他非西势力角色装备区各一张牌",
}

local nobunaga = General(extension, "steam__nobunaga", "west", 4)

local steam__exi = fk.CreateViewAsSkill{
  name = "steam__exi",
  anim_type = "drawcard",
  pattern = ".",
  prompt = "#steam__exi",
  card_filter = function(self, to_select, selected)
    if #selected ~= 0 or not table.contains(Self.player_cards[Player.Hand], to_select) then return false end
    local card = Fk:getCardById(to_select)
    if Fk.currentResponsePattern == nil then
      return Self:canUse(card) and not Self:prohibitUse(card)
    else
      return Exppattern:Parse(Fk.currentResponsePattern):match(card)
    end
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return nil end
    return Fk:getCardById(cards[1])
  end,
  before_use = function(self, player, use)
    local room = player.room
    local current = room.current
    if player:isKongcheng() then return "" end
    room:sendLog{ type = "#steam__exiLog", from = player.id, arg = use.card:toLogString(), toast = true }
    local cid = room:askForCardChosen(current, player, "h", self.name)
    player:showCards({cid})
    local right = (cid == use.card.id)
    room:setCardEmotion(cid, right and "judgegood" or "judgebad")
    room:delay(600)
    if right then
      local players = {player}
      local tos = table.filter(room:getOtherPlayers(player, false), function (p) return not p:isNude() end)
      if #tos > 0 then
        tos = room:askForChoosePlayers(player, table.map(tos, Util.IdMapper), 1, 1, "#steam__exi-choose", self.name, false)
        if #tos > 0 then
          table.insert(players, room:getPlayerById(tos[1]))
        end
      end
      for _, p in ipairs(players) do
        local cards = p:getCardIds("he")
        if #cards > 0 then
          room:recastCard(cards, p, self.name)
        end
      end
      return ""
    else
      use.extra_data = use.extra_data or {}
      use.extra_data.steam__exiDraw = true
    end
  end,
  after_use = function(self, player, use)
    if not player.dead and use.extra_data and use.extra_data.steam__exiDraw then
      local num = player.maxHp - player:getHandcardNum()
      if num > 0 then
        player:drawCards(num, self.name)
      end
    end
  end,
  enabled_at_play = function(self, player)
    return player:getHandcardNum() <= player.maxHp and not player:isKongcheng() and player:usedSkillTimes(self.name) == 0
  end,
  enabled_at_response = function (self, player, response)
    return player:getHandcardNum() <= player.maxHp and not player:isKongcheng() and player:usedSkillTimes(self.name) == 0
    and not response and Fk.currentResponsePattern
    and table.find(player:getCardIds("h"), function (id)
      return Exppattern:Parse(Fk.currentResponsePattern):match(Fk:getCardById(id))
    end)
  end,
}
nobunaga:addSkill(steam__exi)

local steam__buwu = fk.CreateTriggerSkill{
  name = "steam__buwu",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove, fk.Deathed},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.AfterCardsMove then
      local room = player.room
      local ids = {}
      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile and move.from and move.from ~= player.id then
          for _, info in ipairs(move.moveInfo) do
            if room:getCardArea(info.cardId) == Card.DiscardPile and info.fromArea == Card.PlayerEquip then
              local card = Fk:getCardById(info.cardId)
              if player:getEquipment(card.sub_type) == nil and table.every(ids, function (id)
                return Fk:getCardById(id).sub_type ~= card.sub_type
              end) then
                table.insert(ids, info.cardId)
              end
            end
          end
        end
      end
      if #ids > 0 then
        self.cost_data = ids
        return true
      end
    else
      return target ~= player and not (data.damage and data.damage.from == player)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
      room:delay(200)
      room:moveCardIntoEquip(player, self.cost_data, self.name, false, player)
    else
      Fk.game_modes[room.settings.gameMode]:deathRewardAndPunish(target, player)
    end
  end,
}
nobunaga:addSkill(steam__buwu)

Fk:loadTranslationTable{
  ["steam__nobunaga"] = "织田信长",
  ["#steam__nobunaga"] = "第六天魔王",
  ["designer:steam__nobunaga"] = "扬林",
  ["illustrator:steam__nobunaga"] = "信长的野望",

  ["steam__exi"] = "恶戏",
  [":steam__exi"] = "每回合限一次，你需使用手牌中的基本牌或锦囊牌时，若你的手牌数不多于体力上限，你可以声明此牌，且令当前回合角色展示你一张手牌。若不为声明牌，你使用声明牌，再将手牌数补至体力上限。若为声明牌，你令你与一名其他角色依次重铸各自的所有牌。",
  ["#steam__exi-choose"] = "恶戏：选择一名其他角色，你与其各重铸所有牌",
  ["#steam__exi"] = "恶戏：你可以选择并声明一张即将使用的牌，你有可能使用之",
  ["#steam__exiLog"] = "%from 声明了牌 %arg",

  ["steam__buwu"] = "布武",
  [":steam__buwu"] = "锁定技，其他角色的装备牌进入弃牌堆时，若你对应的装备栏无牌，将此牌置入你装备区；其他角色阵亡后，若你不为杀死其的角色，你于结算奖惩后结算一次杀死其身份的奖惩。",
}

local trump = General(extension, "steam__trump", "west", 4)

local zaidi = fk.CreateActiveSkill{
  name = "steam__zaidi",
  prompt = function ()
    return "#steam__zaidi:::"..Self:getMark("@steam__zaidi")
  end,
  anim_type = "offensive",
  card_num = 0,
  min_target_num = 1,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    local to = Fk:currentRoom():getPlayerById(to_select)
    return #selected < Self:getMark("@steam__zaidi") and Self:canPindian(to)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local pd = U.jointPindian(player, table.map(effect.tos, Util.Id2PlayerMapper), self.name)
    local winner = pd.winner
    if winner then
      room:addPlayerMark(winner, "steam__zaidi_win-round")
    end
    local win, lose = 0, 0
    local myNum = pd.fromCard.number
    for _, result in pairs(pd.results) do
      if result.toCard then
        local num = result.toCard.number
        if num > myNum then
          lose = lose + 1
        elseif num < myNum then
          win = win + 1
        end
      end
    end
    if not player.dead then
      if lose > 0 then
        room:addPlayerMark(player, "@steam__zaidi", lose)
      end
      if win > 0 then
        player:drawCards(win, self.name)
      end
    end
  end,
}

local steam__zaidi_trigger = fk.CreateTriggerSkill{
  name = "#steam__zaidi_trigger",
  events = {fk.RoundEnd},
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(zaidi) then
      local maxNum = 0
      for _, p in ipairs(player.room.alive_players) do
        maxNum = math.max(maxNum, p:getMark("steam__zaidi_win-round"))
      end
      if maxNum > 0 then
        local targets = table.map(table.filter(player.room.alive_players, function (p)
          return p:getMark("steam__zaidi_win-round") == maxNum
        end), Util.IdMapper)
        self.cost_data = {tos = targets}
        return true
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    for _, winner in ipairs(table.map(self.cost_data.tos, Util.Id2PlayerMapper)) do
      if not winner.dead then
        local tos = room:askForChoosePlayers(winner, table.map(room.alive_players, Util.IdMapper), 1, 1,
        "#steam__zaidi-damage", zaidi.name, false)
        room:damage { from = winner, to = room:getPlayerById(tos[1]), damage = 1, skillName = zaidi.name }
      end
    end
  end,

  refresh_events = {fk.EventAcquireSkill, fk.EventLoseSkill, fk.BuryVictim, fk.RoundStart},
  can_refresh = function(self, event, target, player, data)
    if event == fk.RoundStart then return player:hasSkill(zaidi, true) end
    if target ~= player then return false end
    if event == fk.BuryVictim then
      return player:hasSkill(zaidi, true, true)
    elseif event == fk.EventLoseSkill then
      return data == zaidi
    elseif event == fk.EventAcquireSkill then
      return data == zaidi
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.RoundStart then
      room:setPlayerMark(player, "@steam__zaidi", 1)
    elseif event == fk.EventAcquireSkill then
      room:setPlayerMark(player, "@steam__zaidi", 1)
      for _, p in ipairs(room:getOtherPlayers(player, false)) do
        room:handleAddLoseSkills(p, "steam__zaidi_other&", nil, false, true)
      end
    else
      if event == fk.EventLoseSkill then
        room:setPlayerMark(player, "@steam__zaidi", 0)
      end
      if table.find(room.alive_players, function (p)
        return p:hasSkill(self, true)
      end) then return end
      for _, p in ipairs(room.alive_players) do
        room:handleAddLoseSkills(p, "-steam__zaidi_other&", nil, false, true)
      end
    end
  end,
}
zaidi:addRelatedSkill(steam__zaidi_trigger)

trump:addSkill(zaidi)

local steam__zaidi_other = fk.CreateActiveSkill{
  name = "steam__zaidi_other&",
  prompt = "#steam__zaidi-other",
  anim_type = "offensive",
  card_num = 0,
  min_target_num = 1,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    local to = Fk:currentRoom():getPlayerById(to_select)
    if not Self:canPindian(to) then return false end
    if #selected == 0 then
      return to:hasSkill(zaidi)
    else
      local first = Fk:currentRoom():getPlayerById(selected[1])
      local num = first:getMark("@steam__zaidi")
      return #selected < num
    end
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local first = room:getPlayerById(effect.tos[1])
    local pd = U.jointPindian(player, table.map(effect.tos, Util.Id2PlayerMapper), zaidi.name)
    local winner = pd.winner
    if winner then
      room:addPlayerMark(winner, "steam__zaidi_win-round")
    end
    local win, lose = 0, 0
    local hisNum = pd.results[first.id].toCard.number
    local myNum = pd.fromCard.number
    if myNum > hisNum then
      lose = 1
    elseif myNum < hisNum then
      win = 1
    end
    for pid, result in pairs(pd.results) do
      if result.toCard and pid ~= first.id then
        local num = result.toCard.number
        if num > hisNum then
          lose = lose + 1
        elseif num < hisNum then
          win = win + 1
        end
      end
    end
    if not first.dead then
      if lose > 0 then
        room:addPlayerMark(first, "@steam__zaidi", lose)
      end
      if win > 0 then
        first:drawCards(win, zaidi.name)
      end
    end
  end,
}
Fk:addSkill(steam__zaidi_other)

local yingji = fk.CreateTriggerSkill{
  name = "steam__yingji",
  frequency = Skill.Compulsory,
  events = {fk.BeforeCardsMove, fk.Damaged, fk.PindianFinished},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.PindianFinished then
      return data.reason == "steam__zaidi" and data.winner == player
    end
    local mark = player:getMark(self.name)
    if mark == 0 then return false end
    if event == fk.BeforeCardsMove then
      for _, move in ipairs(data) do
        if move.from == player.id then
          if table.find(move.moveInfo, function(info)
            return info.fromArea == Card.PlayerHand and table.contains(mark, info.cardId) end)
          then
            return true
          end
        end
      end
    elseif target == player then
      return table.find(mark, function (id)
        return player.room:getCardArea(id) == Card.Void
      end)
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local mark = player:getMark(self.name)
    if event == fk.BeforeCardsMove then
      local ids = {}
      for _, move in ipairs(data) do
        if move.from == player.id then
          local move_info = {}
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand and table.contains(mark, info.cardId) then
              table.insert(ids, info.cardId)
            else
              table.insert(move_info, info)
            end
          end
          move.moveInfo = move_info
        end
      end
      if #ids > 0 then
        table.insert(data, {
          moveInfo = table.map(ids, function (id) return {cardId = id, fromArea = Card.PlayerHand } end),
          from = player.id,
          toArea = Card.Void,
          skillName = self.name,
          moveReason = fk.ReasonJustMove,
          proposer = player.id,
          moveVisible = true,
        })
      end
    elseif event == fk.Damaged then
      local ids = table.filter(mark, function (id)
        return room:getCardArea(id) == Card.Void
      end)
      room:obtainCard(player, ids, true, fk.ReasonJustMove, player.id, self.name)
    else
      for _, p in ipairs(room:getOtherPlayers(player, false)) do
        room:setPlayerMark(p, "@steam__yingji", p:getMark("@steam__yingji") - 1)
        p:filterHandcards()
      end
    end
  end,

  refresh_events = {fk.GameStart},
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(self, true) and not player:isKongcheng()
  end,
  on_refresh = function (self, event, target, player, data)
    local maxNum = 0
    for _, id in ipairs(player.player_cards[Player.Hand]) do
      maxNum = math.max(maxNum, Fk:getCardById(id).number)
    end
    local ids = {}
    for _, id in ipairs(player.player_cards[Player.Hand]) do
      if Fk:getCardById(id).number == maxNum then
        table.insert(ids, id)
        player.room:setCardMark(Fk:getCardById(id), "@@steam__yingji_card", 1)
      end
    end
    player.room:setPlayerMark(player, self.name, ids)
  end,
}

local steam__yingji_filter = fk.CreateFilterSkill{
  name = "#steam__yingji_filter",
  mute = true,
  card_filter = function(self, card, player)
    return player:getMark("@steam__yingji") ~= 0 and card.number > 2
  end,
  view_as = function(self, card, player)
    local c = Fk:cloneCard(card.name, card.suit, card.number + player:getMark("@steam__yingji"))
    c.skillName = yingji.name
    return c
  end,
}
yingji:addRelatedSkill(steam__yingji_filter)

trump:addSkill(yingji)

local ziyou = fk.CreateTriggerSkill{
  name = "steam__ziyou$",
  events = {fk.TurnStart},
  can_trigger = function (self, event, target, player, data)
    return target.kingdom == "west" and player:hasSkill(self)
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    player:chat(Fk:translate("steam__ziyou_chat"))
  end,

  refresh_events = {fk.StartPlayCard},
  can_refresh = function (self, event, target, player, data)
    return player:usedSkillTimes(self.name, Player.HistoryTurn) > 0
  end,
  on_refresh = function (self, event, target, player, data)
    player:chat(Fk:translate("steam__ziyou_chat"..math.random(10)))
  end,
}
trump:addSkill(ziyou)
AddWinAudio(trump)
Fk:loadTranslationTable{
  ["steam__trump"] = "特朗普", -- Donald Trump
  ["#steam__trump"] = "上帝的一票",
  ["designer:steam__trump"] = "yyuaN",
  ["illustrator:steam__trump"] = "",
  ["cv:steam__trump"] = "Donald Trump",

  ["steam__zaidi"] = "再缔",
  [":steam__zaidi"] = "每名角色的出牌阶段限一次，其可与至多[1]名角色共同拼点(拼点角色须含你)：每有一张拼点牌点数小于你的，你摸一张牌，每有一张点数大于你的，本轮[]内数字+1。每轮结束时，本轮以此法赢最多次的角色依次分配1点伤害。",
  ["@steam__zaidi"] = "再缔",
  ["#steam__zaidi"] = "再缔：与至多 %arg 名角色共同拼点",
  ["#steam__zaidi-damage"] = "再缔：请分配1点伤害",
  ["#steam__zaidi-other"] = "再缔：你可以与特朗普拼点！（可能可以额外选择拼点角色）",
  ["steam__zaidi_other&"] = "再缔",
  [":steam__zaidi_other&"] = "出牌阶段限一次，你可与包括特朗普在内至多[1]名角色共同拼点：每有一张拼点牌点数小于其的，其摸一张牌，每有一张点数大于其的，其的【再缔】本轮中[]内数字+1。",
  ["#steam__zaidi_trigger"] = "再缔",

  ["steam__yingji"] = "鹰击",
  [":steam__yingji"] = "你点数最大的起始手牌于失去时移出游戏，并于你受到伤害后加入你的手牌。你因〖再缔〗拼点成为赢者后，令其他角色手牌点数永久-1（至少为1）",
  ["#steam__yingji_filter"] = "鹰击",
  ["@steam__yingji"] = "鹰击",
  ["@@steam__yingji_card"] = "鹰击",

  ["steam__ziyou"] = "自由",
  [":steam__ziyou"] = "主公技，西势力角色的回合内，你可以嘴牌！",
  ["steam__ziyou_chat"] = "本回合中，我将嘴牌！",
  ["steam__ziyou_chat1"] = "我有闪，杀我！",
  ["steam__ziyou_chat2"] = "二号位手里有连弩和桃",
  ["steam__ziyou_chat3"] = "我有桃，随便卖血",
  ["steam__ziyou_chat4"] = "先打三号位，他明反",
  ["steam__ziyou_chat5"] = "留小点给我拼点",
  ["steam__ziyou_chat6"] = "是忠臣就别闪",
  ["steam__ziyou_chat7"] = "怎么不选个李昭仪之类的强力忠臣",
  ["steam__ziyou_chat8"] = "你这么打你是民主党吗？",
  ["steam__ziyou_chat9"] = "给我桃，事成之后封你为能源部长",
  ["steam__ziyou_chat10"] = "早知道选王淩了",

  ["$steam__zaidi1"] = "Together, we will Make America Great Again.",
  ["$steam__zaidi2"] = "We will bring back our jobs, we will bring back our bordors, we will bring back our wealth, and we will bring back our dreams.",
  ["$steam__yingji1"] = "In order to fulfill my solemn duty to protect America and its citizens, the United States will withdraw.",
  ["$steam__yingji2"] = "Stay forward is going to be only America first, America first.",
  ["$steam__ziyou1"] = "I will fight for you with every breath in my body, and I will never ever let you down.",
  ["$steam__ziyou2"] = "As the day the people became the rulers of this nation again.",
  ["$steam__trump_win_audio"] = "God bless you, and God bless America!",
}


local sheldon = General(extension, "steam__sheldon", "west", 3)

local zhuyun = fk.CreateTriggerSkill{
  name = "steam__zhuyun",
  anim_type = "control",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local targets = {}
    room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
      for _, move in ipairs(e.data) do
        if move.from then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              table.insertIfNeed(targets, move.from)
            end
          end
        end
      end
      return false
    end, Player.HistoryTurn)
    if table.contains(targets, player.id) and #targets > 1 then
      local tos = room:askForChoosePlayers(player, targets, 1, 2, "#steam__zhuyun-choose", self.name, true)
      if #tos > 0 then
        room:sortPlayersByAction(tos)
        self.cost_data = {tos = tos}
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = table.map(self.cost_data.tos, Util.Id2PlayerMapper)
    for _, p in ipairs(tos) do
      if not p.dead then
        p:drawCards(1, self.name)
      end
    end
    if table.contains(tos, player) and not player:isKongcheng() then
      local targets = table.filter(room:getOtherPlayers(player, false), function (p) return player:canPindian(p) end)
      tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#steam__zhuyun-pindian", self.name, true)
      if #tos > 0 then
        local to = room:getPlayerById(tos[1])
        local pd = player:pindian({to}, self.name)
        if pd.results[to.id].winner == player then
          RUtil.resetSkill(player, "steam__zanju")
        end
      end
    end
  end,
}
sheldon:addSkill(zhuyun)

---@param player ServerPlayer
local handCardsForThrow = function (player)
  return table.filter(player.player_cards[Player.Hand], function (id)
    return not player:prohibitDiscard(id)
  end)
end

local zanju = fk.CreateTriggerSkill{
  name = "steam__zanju",
  anim_type = "control",
  events = {fk.StartPindian},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryRound) == 0 then
      -- 一个拼点只能开一次赌局
      if (data.extra_data and data.extra_data.steam__zanju_Source) then return false end
      local pd_players = {data.from}
      table.insertTable(pd_players, data.tos)
      for _, p in ipairs(player.room.alive_players) do
        -- 拼点角色至少拥有两张手牌才能参加赌局，不然没牌拼点了
        if #handCardsForThrow(p) > (table.contains(pd_players, p) and 1 or 0) then
          return true
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#steam__zanju-invoke:::"..data.reason)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local pd_players = {data.from}
    table.insertTable(pd_players, data.tos)
    local players = table.filter(room.alive_players, function(p)
      return #handCardsForThrow(p) > (table.contains(pd_players, p) and 1 or 0)
    end)
    if #players == 0 then return end
    data.extra_data = data.extra_data or {}
    data.extra_data.steam__zanju_Source = player.id
    data.extra_datasteam__zanju_Record = {}
    pd_players = table.map(pd_players, Util.IdMapper)

    local moves = {}
    local req = Request:new(players, "AskForUseActiveSkill")
    req.focus_text = self.name
    req.focus_players = players
    local req_data = {
      "steam__zanju_active",
      "#steam__zanju-active",
      false,
      {
        steam__zanju_targets = pd_players,
      },
    }

    for _, p in ipairs(players) do
      req:setData(p, req_data)
    end
    req:ask()
    for _, to in ipairs(players) do
      local cards, tar
      local result = req:getResult(to)
      if result ~= "" then
        cards = result.card.subcards
        tar = result.targets[1]
      else
        cards = table.random(handCardsForThrow(to), 1)
        tar = table.random(pd_players)
      end

      table.insert(moves, {
        from = to.id,
        ids = cards,
        toArea = Card.DiscardPile,
        moveReason = fk.ReasonDiscard,
        moveVisible = true,
        proposer = to.id,
        skillName = self.name,
      })
      room:sendLog{type = "#steam__zanju_guess", from = to.id, to = {tar}}
      data.extra_datasteam__zanju_Record[to.id] = tar
    end
    room:moveCards(table.unpack(moves))
  end,
}

local zanju_delay = fk.CreateTriggerSkill{
  name = "#steam__zanju_delay",
  mute = true,
  events = {fk.PindianFinished},
  can_trigger = function(self, event, target, player, data)
    return data.extra_data and data.extra_data.steam__zanju_Source == player.id
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local winners = {}
    for _, result in pairs(data.results) do
      local winner = result.winner
      if winner then
        table.insert(winners, winner.id)
      end
    end
    local wrong_num = 0
    for pid, tar in pairs(data.extra_datasteam__zanju_Record) do
      local to = room:getPlayerById(pid)
      if table.contains(winners, tar) then
        if not to.dead then
          to:drawCards(2, zanju.name)
        end
      else
        wrong_num = wrong_num + 1
      end
    end
    if wrong_num > 0 and not player.dead then
      player:drawCards(wrong_num, zanju.name)
    end
  end,
}
zanju:addRelatedSkill(zanju_delay)

sheldon:addSkill(zanju)

local zanju_active = fk.CreateActiveSkill{
  name = "steam__zanju_active",
  card_num = 1,
  target_num = 1,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and table.contains(Self.player_cards[Player.Hand], to_select)
    and not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    local to = Fk:currentRoom():getPlayerById(to_select)
    return #selected == 0 and table.contains(self.steam__zanju_targets or {}, to_select)
  end,
}
Fk:addSkill(zanju_active)

Fk:loadTranslationTable{
  ["steam__sheldon"] = "谢尔登", -- Sheldon Gary Adelson
  ["#steam__sheldon"] = "倾天豪掷",
  ["designer:steam__sheldon"] = "杨林",
  ["illustrator:steam__sheldon"] = "AI",

  ["steam__zhuyun"] = "助运",
  [":steam__zhuyun"] = "一名角色的回合结束时，若此回合包括你在内有至少两名角色失去过牌，你可令其中至多两名角色各摸一张牌；若你因此摸牌，你可与一名角色拼点，且若你拼点赢，重置“攒局”的次数。",
  ["#steam__zhuyun-choose"] = "助运：你可以令至多 2 名失去过牌的角色各摸一张牌",
  ["#steam__zhuyun-pindian"] = "助运：你可以与任一角色拼点，若你赢，重置“攒局”",

  ["steam__zanju"] = "攒局",
  [":steam__zanju"] = "轮次技，一次拼点开始时，你可令所有角色依次弃置一张手牌，以此法弃牌的角色同时声明此次拼点赢的角色；拼点结束后，声明与结果相符的角色各摸两张牌，然后你摸X张牌（X为此次声明与结果不符的角色数）。",
  ["#steam__zanju-invoke"] = "攒局：你可以令所有角色弃1张手牌猜测“%arg”拼点的赢家，猜对的摸2张牌，每错1个你摸1张牌",
  ["#steam__zanju-active"] = "攒局：请弃置1张手牌，并选择你猜测的赢家！",
  ["steam__zanju_active"] = "攒局猜测",
  ["#steam__zanju_delay"] = "攒局",
  ["#steam__zanju_guess"] = "%from 猜测 %to 会赢",
}

local steam__musk = General(extension, "steam__musk", "west", 4)

local steam__lianxi = fk.CreateTriggerSkill{
  name = "steam__lianxi",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  -- 竟然没有摸牌后 AfterDrawCard 时机，太坏
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      local tos = {}
      for _, move in ipairs(data) do
        if move.to and move.to ~= player.id and move.toArea == Player.Hand and player.room:getPlayerById(move.to):isAlive()
         and player.room:getPlayerById(move.to).phase ~= Player.Draw then
          if table.find(move.moveInfo, function (info) return info.fromArea == Card.DrawPile end) then
            table.insertIfNeed(tos, move.to)
          end
        end
      end
      if #tos == 1 then
        local to = player.room:getPlayerById(tos[1])
        if table.every(player.room.alive_players, function (p)
          return p == to or p:getHandcardNum() < to:getHandcardNum()
        end) then
          self.cost_data = {tos = tos}
          return true
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    return true
  end,
  on_use = function (self, event, target, player, data)
    player:drawCards(1, self.name)
  end,
}
steam__musk:addSkill(steam__lianxi)

local steam__xinglian = fk.CreateTriggerSkill{
  name = "steam__xinglian",
  events = {fk.EventPhaseStart},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      return player.phase == Player.Start and #player:getPile("steam__xinglian_pile") == 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:addToPile("steam__xinglian_pile", room:getNCards(4), true, self.name)
  end,
}

local steam__xinglian_exchange = fk.CreateTriggerSkill{
  name = "#steam__xinglian_exchange",
  mute = true,
  main_skill = steam__lianxi,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(steam__lianxi) and #player:getPile("steam__xinglian_pile") > 0 and not player:isKongcheng() then
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Player.Hand and move.skillName ~= "steam__xinglian" then
          return true
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#steam__xinglian-invoke")
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to_ex = U.askForExchange(player, "steam__xinglian_pile", "$Hand",
    player:getPile("steam__xinglian_pile"), player:getCardIds("h"), "#steam__xinglian-exchange", 1)
    if #to_ex == 0 then return end
    local get, put
    if table.contains(player:getCardIds("h"), to_ex[1]) then
      put, get = to_ex[1], to_ex[2]
    else
      put, get = to_ex[2], to_ex[1]
    end
    U.swapCardsWithPile(player, {put}, {get}, "steam__xinglian", "steam__xinglian_pile", false, player.id)
    if not player.dead then
      local num = 0
      for _, id in ipairs(player:getPile("steam__xinglian_pile")) do
        num = num + Fk:getCardById(id).number
      end
      if num == 24 then
        room:obtainCard(player, player:getPile("steam__xinglian_pile"), true, fk.ReasonJustMove, player.id, "steam__xinglian")
      end
    end
  end,
}
steam__xinglian:addRelatedSkill(steam__xinglian_exchange)

steam__musk:addSkill(steam__xinglian)

Fk:loadTranslationTable{
  ["steam__musk"] = "马斯克", -- Elon Musk
  ["#steam__musk"] = "硅谷钢铁侠",
  ["illustrator:steam__musk"] = "AI",
  ["designer:steam__musk"] = "杨林",

  ["steam__lianxi"] = "联席",
  [":steam__lianxi"] = "锁定技，其他角色于摸牌阶段外摸牌后，若其手牌数为场上唯一最多，你摸一张牌。",

  ["steam__xinglian"] = "星链",
  [":steam__xinglian"] = "锁定技，准备阶段，若你无星链牌，你将牌堆顶的四张牌置于武将牌上。你不因此技能获得牌后，你可用一张手牌替换一张星链牌；然后若星链牌的点数之和等于24，你获得这些牌。",
  ["steam__xinglian_pile"] = "星链",
  ["#steam__xinglian_exchange"] = "星链",
  ["#steam__xinglian-invoke"] = "星链：你可用一张牌替换一张星链牌，若星链牌点数和为24，你获得之",
  ["#steam__xinglian-exchange"] = "用一张牌替换一张星链牌，若星链牌点数和为24，你获得之",
}

local simayi = General(extension, "steam__simayi", "jin", 3)
local taozhu = fk.CreateTriggerSkill{
  name = "steam__taozhu",
  anim_type = "control",
  events = {fk.CardUsing, fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.CardUsing then
        return data.card.type == Card.TypeTrick
      elseif event == fk.DamageInflicted then
        return true
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local prompt = event == fk.CardUsing and "taozhu_cardusing" or "taozhu_damage"
    local choices = {"steam__taozhu1:::"..prompt, "draw1", "Cancel"}
    local to = nil
    if event == fk.CardUsing then
      room.logic:getEventsByRule(GameEvent.UseCard, 1, function (e)
        if e.id ~= room.logic:getCurrentEvent().id then
          local use = e.data[1]
          if use.card.type == Card.TypeTrick then
            to = room:getPlayerById(use.from)
            return true
          end
        end
      end, 1)
    elseif event == fk.DamageInflicted then
      room.logic:getActualDamageEvents(1, function (e)
        if e.id ~= room.logic:getCurrentEvent().id then
          to = e.data[1].to
          return true
        end
      end, nil, 1)
    end
    if to and not to.dead then
      prompt = event == fk.CardUsing and "taozhu_canceluse" or "taozhu_canceldamage"
      choices[2] = "steam__taozhu2:"..target.id..":"..to.id..":"..prompt
    end
    local choice = room:askForChoice(player, choices, self.name)
    if choice ~= "Cancel" then
      if choice:startsWith("steam__taozhu2") and to then
        self.cost_data = {tos = {to.id}, choice = choice}
        return true
      else
        self.cost_data = {choice = choice}
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if self.cost_data.choice:startsWith("steam__taozhu1") then
      local info = string.split(self.cost_data.choice, ":")
      room:setPlayerMark(player, "@@steam__"..info[4], 1)
    else
      player:drawCards(1, self.name)
      if player.dead then return end
      if self.cost_data.choice:startsWith("steam__taozhu2") then
        local to = room:getPlayerById(self.cost_data.tos[1])
        if to.dead or not player:canPindian(to) then return end
        local pindian = player:pindian({to}, self.name)
        if pindian.results[to.id].winner ~= player then
          if event == fk.CardUsing then
            data.tos = {}
          elseif event == fk.DamageInflicted then
            return true
          end
        end
      end
    end
  end,
}
local taozhu_delay = fk.CreateTriggerSkill{
  name = "#steam__taozhu_delay",
  priority = 2,
  anim_type = "control",
  events = {fk.CardUsing, fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if event == fk.CardUsing and data.card.type == Card.TypeTrick then
      return player:getMark("@@steam__taozhu_cardusing") > 0
    elseif event == fk.DamageInflicted then
      return player:getMark("@@steam__taozhu_damage") > 0
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})
    if event == fk.CardUsing and data.card.type == Card.TypeTrick then
      room:setPlayerMark(player, "@@steam__taozhu_cardusing", 0)
    elseif event == fk.DamageInflicted then
      room:setPlayerMark(player, "@@steam__taozhu_damage", 0)
    end
    if target.dead or target:isNude() then return end
    local flag = "he"
    if target == player then
      if #player:getCardIds("e") == 0 then return end
      flag = "e"
    end
    local card = room:askForCardChosen(player, target, flag, "steam__taozhu", "#steam__taozhu-prey::"..target.id)
    room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonPrey, "steam__taozhu", nil, false, player.id)
  end,
}
local tuigong = fk.CreateTriggerSkill{
  name = "steam__tuigong",
  mute = true,
  events = {fk.DamageCaused, fk.RoundEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:getMark(self.name) == 0 then
      if event == fk.DamageCaused then
        return target == player and data.damage >= data.to.hp + data.to.shield and
          not data.to.dead and player:canUseTo(Fk:cloneCard("sincere_treat"), data.to, {bypass_distances = true})
      elseif event == fk.RoundEnd then
        local to = nil
        for _, p in ipairs(player.room.alive_players) do
          if #p:getCardIds("ej") > 0 then
            if to ~= nil then return end
            if #p:getCardIds("ej") > 1 then
              return
            else
              to = p
            end
          end
        end
        if to == nil then return end
        if player.room:canMoveCardInBoard(nil, {to}) then
          self.cost_data = {tos = {to.id}}
          return true
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    if event == fk.DamageCaused then
      if room:askForSkillInvoke(player, self.name, nil,
        "#steam__tuigong-invoke::"..data.to.id..":"..player:getMark("@steam__tuigong")) then
        self.cost_data = {tos = {data.to.id}}
        return true
      end
    elseif event == fk.RoundEnd then
      return room:askForSkillInvoke(player, self.name, nil, "#steam__tuigong-add::"..self.cost_data.tos[1])
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    if event == fk.DamageCaused then
      room:notifySkillInvoked(player, self.name, "big")
      room:setPlayerMark(player, self.name, 1)
      local n = player:getMark("@steam__tuigong")
      room:setPlayerMark(player, "@steam__tuigong", 0)
      for i = 1, n, 1 do
        if player.dead or data.to.dead then return end
        room:useVirtualCard("sincere_treat", nil, player, data.to, self.name)
      end
    elseif event == fk.RoundEnd then
      room:notifySkillInvoked(player, self.name, "control")
      room:addPlayerMark(player, "@steam__tuigong", 1)
      local tos = room:askForChooseToMoveCardInBoard(player, "#steam__tuigong-move", self.name, false, nil, false)
      local targets = table.map(tos, Util.Id2PlayerMapper)
      room:askForMoveCardInBoard(player, targets[1], targets[2], self.name)
    end
  end,

  on_acquire = function (self, player, is_start)
    player.room:setPlayerMark(player, "@steam__tuigong", 3)
  end,
  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player, "@steam__tuigong", 0)
  end,
}
taozhu:addRelatedSkill(taozhu_delay)
simayi:addSkill(taozhu)
simayi:addSkill(tuigong)
Fk:loadTranslationTable{
  ["steam__simayi"] = "司马懿",
  ["#steam__simayi"] = "",
  ["illustrator:steam__simayi"] = "凝聚永恒",
  ["designer:steam__simayi"] = "初长风",

  ["steam__taozhu"] = "韬逐",
  [":steam__taozhu"] = "当你使用锦囊牌或受到伤害时，你可以选择一项：1.获得下名执行本操作的角色一张牌；2.摸一张牌，然后与上名执行本操作的角色拼点，"..
  "若你没赢，取消之。",
  ["steam__tuigong"] = "推宫",
  [":steam__tuigong"] = "每局游戏限一次，当你造成致命伤害时，你可以视为对其使用(3)张【推心置腹】。此前轮次结束时，你可以令此值+1并移动场上"..
  "唯一的牌。",

  ["steam__taozhu1"] = "下一名角色%arg时，你获得其一张牌",
  ["steam__taozhu2"] = "摸一张牌并与 %dest 拼点，若你没赢，%src %arg",
  ["taozhu_cardusing"] = "使用锦囊牌",
  ["taozhu_damage"] = "受到伤害",
  ["taozhu_canceluse"] = "取消使用的锦囊",
  ["taozhu_canceldamage"] = "防止受到的伤害",
  ["@@steam__taozhu_cardusing"] = "韬逐 使用锦囊",
  ["@@steam__taozhu_damage"] = "韬逐 受到伤害",
  ["#steam__taozhu_delay"] = "韬逐",
  ["#steam__taozhu-prey"] = "韬逐：获得 %dest 一张牌",
  ["#steam__tuigong-invoke"] = "推宫：是否视为对 %dest 使用%arg张【推心置腹】？",
  ["@steam__tuigong"] = "推宫",
  ["#steam__tuigong-add"] = "推宫：是否令“推宫”张数+1并移动 %dest 场上的牌？",
  ["#steam__tuigong-move"] = "推宫：请移动场上的牌",

  ["$steam__taozhu1"] = "善瞻者察微于九地之下！",
  ["$steam__taozhu2"] = "善谋者鹰扬于九天之上！",
  ["$steam__tuigong1"] = "以退为进，俗子焉能度之。",
  ["$steam__tuigong2"] = "应时而变，当行权宜之计。",
  ["~steam__simayi"] = "大业五十年，说与山鬼听……",
}

local simashi = General(extension, "steam__simashi", "jin", 3)
local maishi = fk.CreateFilterSkill{
  name = "steam__maishi",
  card_filter = function(self, card, player, isJudgeEvent)
    return player:hasSkill(self) and player.phase ~= Player.NotActive and player:getMark("steam__maishi-turn") == 0 and
    card.color == Card.Black and table.contains(player:getCardIds("h"), card.id)
  end,
  view_as = function(self, card)
    return Fk:cloneCard("steam__underhanding", card.suit, card.number)
  end,
}
local maishi_trigger = fk.CreateTriggerSkill{
  name = "#steam__maishi_trigger",

  refresh_events = {fk.AfterCardUseDeclared},
  can_refresh = function(self, event, target, player, data)
    return target == player and player.phase ~= Player.NotActive and data.card.type == Card.TypeTrick
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "steam__maishi-turn", 1)
  end,
}
local ruilve = fk.CreateActiveSkill{
  name = "steam__ruilve",
  anim_type = "drawcard",
  min_card_num = 1,
  target_num = 0,
  prompt = "#steam__ruilve",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return Fk:getCardById(to_select, false).type == Card.TypeTrick
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:recastCard(effect.cards, player, self.name)
    if player.dead then return end
    local cards = table.filter(effect.cards, function (id)
      if table.contains(room.discard_pile, id) then
        local card = Fk:getCardById(id)
        return player:canUse(card, { bypass_times = true }) and not player:prohibitUse(card)
      end
    end)
    if #cards == 0 then return end
    U.askForUseRealCard(room, player, cards, nil, self.name, "#steam__ruilve-use", { expand_pile = cards, bypass_times = true })
  end
}
local getShade = function (room, n)
  local ids = {}
  local name
  if Fk.all_card_types["shade"] then
    name = "shade"
  elseif Fk.all_card_types["rfenghou__shade"] then
    name = "rfenghou__shade"
  end
  assert(name, "服务器未加入【影】！请联系管理员安装“江山如故”或“封侯”包")
  for _, id in ipairs(room.void) do
    if n <= 0 then break end
    if Fk:getCardById(id).name == name then
      room:setCardMark(Fk:getCardById(id), MarkEnum.DestructIntoDiscard, 1)
      table.insert(ids, id)
      n = n - 1
    end
  end
  while n > 0 do
    local card = room:printCard(name, Card.Spade, 1)
    room:setCardMark(card, MarkEnum.DestructIntoDiscard, 1)
    table.insert(ids, card.id)
    n = n - 1
  end
  return ids
end
local fuyu = fk.CreateTriggerSkill{
  name = "steam__fuyu",
  anim_type = "support",
  frequency = Skill.Compulsory,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
      table.find(player.room.alive_players, function (p)
        return Fk.generals[p.general].trueName:startsWith("sima")
      end)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function (p)
      return Fk.generals[p.general].trueName:startsWith("sima")
    end)
    local to
    if #targets == 1 then
      to = {player.id}
    else
      to = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#steam__fuyu-choose", self.name, false)
    end
    room:moveCardTo(getShade(room, 1), Card.PlayerHand, to[1], fk.ReasonJustMove, self.name, nil, true, player.id)
  end,
}
maishi:addRelatedSkill(maishi_trigger)
simashi:addSkill(maishi)
simashi:addSkill(ruilve)
simashi:addSkill(fuyu)
Fk:loadTranslationTable{
  ["steam__simashi"] = "司马师",
  ["#steam__simashi"] = "韬隐沉略",
  ["illustrator:steam__simashi"] = "拉布拉卡",
  ["designer:steam__simashi"] = "胖即是胖",

  ["steam__maishi"] = "埋士",
  [":steam__maishi"] = "锁定技，你的回合内，若你本回合未使用过锦囊牌，你的所有黑色手牌均视为【瞒天过海】。",
  ["steam__ruilve"] = "睿略",
  [":steam__ruilve"] = "出牌阶段限一次，你可以重铸任意张锦囊牌，然后你可以使用其中的一张牌。",
  ["steam__fuyu"] = "伏慾",
  [":steam__fuyu"] = "宗族技，当你使用牌结算后，你令一名同宗族角色获得一张【影】。",
  ["#steam__ruilve"] = "睿略：你可以重铸任意张锦囊牌，然后可以使用其中一张牌",
  ["#steam__ruilve-use"] = "睿略：你可以使用其中一张牌",
  ["#steam__fuyu-choose"] = "伏慾：令一名同族角色获得一张【影】",

  ["$steam__ruilve1"] = "司马氏满门英杰，皆经天纬地之才！",
  ["$steam__ruilve2"] = "外知军略，内通政事，此乃明君之象。",
  ["$steam__fuyu1"] = "成大事者，当务实权而远虚名！",
  ["$steam__fuyu2"] = "潜龙隐于千丈海，胸有韬晦十万兵。",
  ["~steam__simashi"] = "司马师",
}

local simayiw = General(extension, "steam__simayiw", "jin", 4)
local tongkai = fk.CreateTriggerSkill{
  name = "steam__tongkai",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecifying},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.card.trueName == "slash" and #AimGroup:getAllTargets(data.tos) == 1 then
      local to = player.room:getPlayerById(data.to)
      for _, p in ipairs({player, to}) do
        if table.find(p:getCardIds("he"), function (id)
          return not p:prohibitDiscard(id)
        end) then
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = {}
    local to = room:getPlayerById(data.to)
    for _, p in ipairs({player, to}) do
      if table.find(p:getCardIds("he"), function (id)
        return not p:prohibitDiscard(id)
      end) then
        table.insert(tos, p.id)
      end
    end
    local target = room:askForChoosePlayers(player, tos, 1, 1, "#steam__tongkai-choose", self.name, false)
    target = room:getPlayerById(target[1])

    local choices = {}
    tos = {}
    if target:getNextAlive() ~= to and target:getNextAlive() ~= player and
      not player:isProhibited(target:getNextAlive(), data.card) then
      table.insert(tos, target:getNextAlive().id)
      table.insert(choices, "steam__tongkai1")
    end
    if target:getLastAlive() ~= to and target:getLastAlive() ~= player and
      not player:isProhibited(target:getLastAlive(), data.card) then
      table.insert(tos, target:getLastAlive().id)
      table.insertIfNeed(choices, "steam__tongkai1")
    end
    if table.find(target:getCardIds("he"), function (id)
      return not target:prohibitDiscard(id)
    end) then
      table.insert(choices, "steam__tongkai2")
    end
    local cards = table.filter(target:getCardIds("he"), function (id)
      return not target:prohibitDiscard(id)
    end)
    if #choices == 2 and #cards > 1 then
      table.insert(choices, "steam__tongkai_beishui")
    end

    local choice = room:askForChoice(target, choices, self.name, nil, false,
      {"steam__tongkai1", "steam__tongkai2", "steam__tongkai_beishui"})
    if choice ~= "steam__tongkai2" then
      local num = choice == "steam__tongkai_beishui" and 2 or 1
      local victim, ids = room:askForChooseCardsAndPlayers(target, num, num, tos, 1, 1, tostring(Exppattern{ id = cards }),
        "#steam__tongkai-transfer:::"..num, self.name, false, false)
      room:throwCard(ids, self.name, target, target)
      AimGroup:cancelTarget(data, data.to)
      AimGroup:addTargets(room, data, victim[1])
    end
    if choice ~= "steam__tongkai1" then
      if choice == "steam__tongkai2" then
        room:askForDiscard(target, 1, 1, true, self.name, false)
      end
      data.additionalDamage = (data.additionalDamage or 0) + 1
    end
    if choice == "steam__tongkai_beishui" then
      data.extra_data = data.extra_data or {}
      data.extra_data.steam__tongkai_draw = data.extra_data.steam__tongkai_draw or {}
      data.extra_data.steam__tongkai_draw[target.id] = (data.extra_data.steam__tongkai_draw[target.id] or 0) + 1
    end
  end,
}
local tongkai_delay = fk.CreateTriggerSkill{
  name = "#steam__tongkai_delay",
  mute = true,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return not player.dead and data.extra_data and data.extra_data.steam__tongkai_draw and
    data.extra_data.steam__tongkai_draw[player.id]
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    player:drawCards(2 * data.extra_data.steam__tongkai_draw[player.id], "steam__tongkai")
  end,
}
tongkai:addRelatedSkill(tongkai_delay)
simayiw:addSkill(tongkai)
Fk:loadTranslationTable{
  ["steam__simayiw"] = "司马乂",
  ["#steam__simayiw"] = "",
  ["illustrator:steam__simayiw"] = "",
  ["designer:steam__simayiw"] = "末折",

  ["steam__tongkai"] = "同忾",
  [":steam__tongkai"] = "锁定技，你使用【杀】指定唯一目标时，你令你或其执行一项：<br>"..
  "1.弃置一张牌，此牌重新指定其一名邻家为目标；<br>2.弃置一张牌，此牌造成的伤害加1。<br>背水：此牌结算后，摸两张牌。",
  ["#steam__tongkai-choose"] = "同忾：请令一名角色选择一项",
  ["steam__tongkai1"] = "弃一张牌，重新指定你一名邻家为此【杀】目标",
  ["steam__tongkai2"] = "弃一张牌，此【杀】伤害加1",
  ["steam__tongkai_beishui"] = "背水：此【杀】结算后你摸两张牌",
  ["#steam__tongkai-transfer"] = "同忾：弃%arg张牌，重新选择此【杀】的目标",
  ["#steam__tongkai_delay"] = "同忾",
}

local steam__underhandingSkill = fk.CreateActiveSkill{
  name = "steam__underhanding_skill",
  prompt = "#steam__underhanding_skill",
  can_use = Util.CanUse,
  min_target_num = 1,
  max_target_num = 2,
  mod_target_filter = function(self, to_select, selected, user, card)
    return user.id ~= to_select and not Fk:currentRoom():getPlayerById(to_select):isAllNude()
  end,
  target_filter = Util.TargetFilter,
  on_effect = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.to)
    if not to:isAllNude() then
      local id = room:askForCardChosen(player, to, "hej", self.name)
      room:obtainCard(player, id, false, fk.ReasonPrey, player.id, self.name)
      local e = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      if e then
        local use = e.data[1]
        use.extra_data = use.extra_data or {}
        use.extra_data.steam__underhanding_targets = use.extra_data.steam__underhanding_targets or {}
        table.insertIfNeed(use.extra_data.steam__underhanding_targets, to.id)
      end
    end
  end,
  on_action = function (self, room, use, finished)
    if not finished then return end
    local player = room:getPlayerById(use.from)
    if player.dead or player:isNude() then return end
    local targets = (use.extra_data or {}).steam__underhanding_targets or {}
    if #targets == 0 then return end
    room:sortPlayersByAction(targets)
    for _, pid in ipairs(targets) do
      local target = room:getPlayerById(pid)
      if not player:isNude() and not target.dead and not player.dead then
        local c = room:askForCard(player, 1, 1, true, self.name, false, nil, "#steam__underhanding-card::" .. pid)[1]
        room:moveCardTo(c, Player.Hand, target, fk.ReasonGive, self.name, nil, false, player.id)
      end
    end
  end
}
local steam__underhandingExclude = fk.CreateMaxCardsSkill{
  name = "steam__underhanding_exclude",
  global = true,
  exclude_from = function(self, player, card)
    return card and card.name == "steam__underhanding"
  end,
}
Fk:addSkill(steam__underhandingExclude)
local steam__underhanding = fk.CreateTrickCard{
  name = "&steam__underhanding",
  suit = Card.Heart,
  number = 5,
  skill = steam__underhandingSkill,
  multiple_targets = true,
}
steam__underhanding.package = extension
Fk:addCard(steam__underhanding)
Fk:loadTranslationTable{
  ["steam__underhanding"] = "瞒天过海",
  [":steam__underhanding"] = "锦囊牌<br /><b>时机</b>：出牌阶段<br /><b>目标</b>：一至两名区域内有牌的其他角色。<br/><b>效果</b>："..
  "你依次获得目标角色区域内的一张牌，然后依次交给目标角色一张牌。<br/>此牌不计入你的手牌上限。",
  ["steam__underhanding_skill"] = "瞒天过海",
  ["steam__underhanding_action"] = "瞒天过海",
  ["#steam__underhanding-card"] = "瞒天过海：交给 %dest 一张牌",
  ["#steam__underhanding_skill"] = "选择一至两名区域内有牌的其他角色，依次获得其区域内的一张牌，然后依次交给其一张牌",
}

local yuquan = General(extension, "steam__yuquan", "wu", 2, 5)

local steam__mianzhou = fk.CreateTriggerSkill{
  name = "steam__mianzhou",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player and #player:getCardIds("e") == 0 then
      return data.damage >= (player.hp + player.shield)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, -1)
    if player.dead then return end
    local targets = table.map(room:getOtherPlayers(player, false), Util.IdMapper)
    if #targets > 0 then
      local tos = room:askForChoosePlayers(player, targets, 1, 1, "#steam__mianzhou-choose", self.name, false)
      if #tos > 0 then
        local to = room:getPlayerById(tos[1])
        local choices = {"basic", "trick", "equip"}
        if player:usedSkillTimes(self.name) < 2 then table.remove(choices, 1) end
        local cardType = room:askForChoice(player, choices, self.name, "#steam__mianzhou-choice:"..to.id) .. "_char"
        local mark = to:getTableMark("@steam__mianzhou-turn")
        if table.insertIfNeed(mark, cardType) then
          room:setPlayerMark(to, "@steam__mianzhou-turn", mark)
        end
      end
    end
    return true
  end,
}
local steam__mianzhou_prohibit = fk.CreateProhibitSkill{
  name = "#steam__mianzhou_prohibit",
  prohibit_use = function(self, player, card)
    return card and table.contains(player:getTableMark("@steam__mianzhou-turn"), card:getTypeString() .. "_char")
  end,
}
steam__mianzhou:addRelatedSkill(steam__mianzhou_prohibit)

yuquan:addSkill(steam__mianzhou)

local steam__fuzhen = fk.CreateTriggerSkill{
  name = "steam__fuzhen",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target ~= player and not target.dead then
      return target.phase == Player.Start and target:inMyAttackRange(player)
    end
  end,
  on_cost = function (self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name, nil, "#steam__fuzhen-invoke:"..target.id.."::"..player:getLostHp()) then
      self.cost_data = {tos = {target.id}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addTableMark(target, "@@steam__fuzhen-turn", player.id)
    player:drawCards(player:getLostHp(), self.name)
  end,
}
local steam__fuzhen_prohibit = fk.CreateProhibitSkill{
  name = "#steam__fuzhen_prohibit",
  is_prohibited = function (self, player, to, card)
    if not player then return false end
    local mark = player:getTableMark("@@steam__fuzhen-turn")
    if #mark == 0 then return false end
    if card and card.is_damage_card then
      return #mark > 1 or not table.contains(mark, to.id)
    end
  end,
}
steam__mianzhou:addRelatedSkill(steam__fuzhen_prohibit)

yuquan:addSkill(steam__fuzhen)

Fk:loadTranslationTable{
  ["steam__yuquan"] = "于诠",
  ["#steam__yuquan"] = "杀身成仁",
  ["illustrator:steam__yuquan"] = "",
  ["designer:steam__yuquan"] = "颜渊",

  ["steam__mianzhou"] = "免胄",
  [":steam__mianzhou"] = "锁定技，若你的装备区没有牌，当你受到致命伤害时，改为减少1点体力上限，然后令一名其他角色本回合不能使用一种类型的牌（每回合首次发动不可选择基本牌）。",
  ["@steam__mianzhou-turn"] = "免胄",
  ["#steam__mianzhou-choose"] = "免胄：令一名其他角色本回合不能使用一种类型的牌",
  ["#steam__mianzhou-choice"] = "免胄：选择令 %src 本回合不能使用一种类型的牌",

  ["steam__fuzhen"] = "赴阵",
  [":steam__fuzhen"] = "其他角色的准备阶段，若你在其攻击范围内，你可以令其本回合使用伤害类牌只能指定你为目标，然后你摸已损失体力值张牌。",
  ["#steam__fuzhen-invoke"] = "赴阵：你可以令 %src 本回合伤害牌只能指定你为目标，然后你摸 %arg 张牌",
  --["#steam__fuzhen-cost"] = "赴阵：你可以弃置两张牌并增加1点体力上限",
  ["@@steam__fuzhen-turn"] = "被赴阵",
}

local zhangte = General(extension, "steam__zhangte", "wei", 4)

local steam__buzhu = fk.CreateActiveSkill{
  name = "steam__buzhu",
  anim_type = "support",
  min_card_num = 1,
  target_num = 1,
  prompt = "#steam__buzhu",
  card_filter = function(self, to_select, selected)
    return Fk:getCardById(to_select).type ~= Card.TypeEquip
    and not Self:prohibitUse(Fk:getCardById(to_select)) and Self:canUse(Fk:getCardById(to_select))
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and #selected_cards > 0
  end,
  can_use = function(self, player)
    return not player:isKongcheng()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    room:throwCard(effect.cards, self.name, player, player)
    if to.dead then return end
    local ids = room:getCardsFromPileByRule(".|.|.|.|.|equip", #effect.cards)
    if #ids == 0 then return end
    room:obtainCard(to, ids, true, fk.ReasonJustMove, player.id, self.name)
    while to:isAlive() do
      ids = table.filter(ids, function(id)
        return table.contains(to:getCardIds("h"), id)
      end)
      -- stupid filter skill...
      for _, id in ipairs(ids) do
        Fk:filterCard(id, to)
      end
      ids = table.filter(ids, function(id)
        return Fk:getCardById(id).type == Card.TypeEquip and to:canUseTo(Fk:getCardById(id), to)
        and to:hasEmptyEquipSlot(Fk:getCardById(id).sub_type)
      end)
      if #ids == 0 then break end
      local cid = table.random(ids)
      local same = table.filter(ids, function(id)
        return Fk:getCardById(cid).sub_type == Fk:getCardById(id).sub_type
      end)
      if #same > 1 then
        same = room:askForCard(to, 1, 1, false, self.name, false, tostring(Exppattern{ id = same }), "#steam__buzhu-use")
      end
      table.removeOne(ids, same[1]) -- 谨防防止移动导致的死循环
      room:useCard{from = to.id, tos = {{to.id}}, card = Fk:getCardById(same[1])}
    end
  end,
}
zhangte:addSkill(steam__buzhu)

local steam__zhenyu = fk.CreateTriggerSkill{
  name = "steam__zhenyu",
  anim_type = "support",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and not target.dead and #target:getCardIds("e") > 0
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#steam__zhenyu-invoke:"..target.id)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local equps = target:getCardIds("e")
    local cid = equps[1]
    if #equps > 1 then
      -- 哈哈，用这个函数可以看见卡牌标记
      cid = U.askforChooseCardsAndChoice(player, equps, {"OK"}, self.name, "$ChooseCard", {}, 1, 1)[1]
    end
    local good = Fk:getCardById(cid):getMark("@@steam__buzhu_card") ~= 0
    room:throwCard({cid}, self.name, target, player)
    if not target.dead then
      room:recover { num = 1, skillName = self.name, who = target, recoverBy = player }
    end
    if good then
      if not target.dead then
        local x = math.min(5, target.maxHp - target:getHandcardNum())
        if x > 0 then
          target:drawCards(x, self.name)
        end
      end
    else
      if not player.dead then
        room:loseHp(player, 1, self.name)
      end
    end
  end,

  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    return player.seat == 1
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    --- 检测是否因为“补筑”而移入装备区
    local skillCheck = function ()
      local currentEvent = room.logic:getCurrentEvent()
      if currentEvent.parent and currentEvent.parent.event == GameEvent.UseCard then
        local skillEvent = currentEvent.parent.parent
        return skillEvent and skillEvent.event == GameEvent.SkillEffect
        and skillEvent.data and skillEvent.data[3] and skillEvent.data[3].name == "steam__buzhu"
      end
    end
    for _, move in ipairs(data) do
      for _, info in ipairs(move.moveInfo) do
        if info.fromArea == Player.Equip then
          if Fk:getCardById(info.cardId):getMark("@@steam__buzhu_card") ~= 0 then
            room:setCardMark(Fk:getCardById(info.cardId), "@@steam__buzhu_card", 0)
          end
        end
      end
      if move.toArea == Player.Equip then
        if skillCheck() then
          for _, info in ipairs(move.moveInfo) do
            room:setCardMark(Fk:getCardById(info.cardId), "@@steam__buzhu_card", 1)
          end
        end
      end
    end
  end,
}
zhangte:addSkill(steam__zhenyu)

Fk:loadTranslationTable{
  ["steam__zhangte"] = "张特",
  ["#steam__zhangte"] = "缓兵之策",
  ["illustrator:steam__zhangte"] = "",
  ["designer:steam__zhangte"] = "颜渊",

  ["steam__buzhu"] = "补筑",
  [":steam__buzhu"] = "出牌阶段，你可以弃置任意张可以使用的非装备牌，令一名角色从牌堆获得等量张装备牌，若其有对应的空置装备栏，使用之。",
  ["#steam__buzhu"] = "补筑:弃置任意张可以使用的非装备牌，令一名角色获得等量张装备牌",
  ["#steam__buzhu-use"] = "补筑：请选择一张装备牌使用！",
  ["@@steam__buzhu_card"] = "补筑",

  ["steam__zhenyu"] = "镇御",
  [":steam__zhenyu"] = "一名角色受到伤害后，你可以弃置其装备区一张牌，令其回复1点体力，若为“补筑”牌，其摸牌至体力上限（至多摸5张）；否则你失去1点体力。",
  ["#steam__zhenyu-invoke"] = "镇御:你可以弃置 %src 装备区一张牌，令其回复1点体力",
}


local dongmindonghuang = General(extension, "steam__dongmindonghuang", "qun", 4)
local ciheng = fk.CreateTriggerSkill{
  name = "steam__ciheng",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play and
      #player.room.alive_players > 1
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local tos = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 2, 2,
      "#steam__ciheng-choose", self.name)
    if #tos > 0 then
      room:sortPlayersByAction(tos)
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(self.cost_data.tos, Util.Id2PlayerMapper)
    for _, p in ipairs(targets) do
      room:setPlayerMark(p, "@@steam__ciheng-turn", 1)
      room:handleAddLoseSkills(p, "steam__ciheng&", nil, false, true)
      room.logic:getCurrentEvent():findParent(GameEvent.Turn):addCleaner(function()
        room:handleAddLoseSkills(p, "-steam__ciheng&", nil, false, true)
      end)
    end
    targets = table.filter(targets, function (p)
      return not p:isKongcheng()
    end)
    if #targets > 0 then
      local result = U.askForJointCard(targets, 1, 999, false, self.name, true, nil, "#steam__ciheng-ask")
      for _, ids in pairs(result) do
        if #ids > 0 then
          for _, id in ipairs(ids) do
            room:setCardMark(Fk:getCardById(id), "@@steam__ciheng-inhand-turn", 1)
          end
        end
      end
    end
  end,
}
local ciheng_delay = fk.CreateTriggerSkill{
  name = "#steam__ciheng_delay",
  anim_type = "control",
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    return target == player and player.phase == Player.Play and player:usedSkillTimes("steam__ciheng", Player.HistoryPhase) > 0 and
      table.find(player.room.alive_players, function (p)
        return p:getMark("@@steam__ciheng-turn") > 0
      end)
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getAlivePlayers()) do
      if p:getMark("@@steam__ciheng-turn") > 0 then
        local cards = table.filter(p:getCardIds("h"), function (id)
          local card = Fk:getCardById(id, false)
          return card:getMark("@@steam__ciheng-inhand-turn") == 0 and card.trueName ~= "duel" and not p:prohibitDiscard(id)
        end)
        if #cards > 0 then
          room:throwCard(cards, "steam__ciheng", p, p)
        end
      end
    end
  end,
}
local ciheng_filter = fk.CreateFilterSkill{
  name = "#steam__ciheng_filter",
  anim_type = "offensive",
  card_filter = function(self, card, player, isJudgeEvent)
    return card:getMark("@@steam__ciheng-inhand-turn") > 0 and table.contains(player:getCardIds("h"), card.id)
  end,
  view_as = function(self, card)
    return Fk:cloneCard("duel", card.suit, card.number)
  end,
}
local ciheng_prohibit = fk.CreateProhibitSkill{
  name = "#steam__ciheng_prohibit",
  is_prohibited = function (self, from, to, card)
    return from:usedSkillTimes("steam__ciheng", Player.HistoryPhase) > 0 and card and
      to:getMark("@@steam__ciheng-turn") == 0
  end,
}
local ciheng_viewas = fk.CreateViewAsSkill{
  name = "steam__ciheng&",
  anim_type = "offensive",
  pattern = "slash",
  prompt = "#steam__ciheng&",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and table.contains(Self:getCardIds("h"), to_select) and
      Fk:getCardById(to_select):getMark("@@steam__ciheng-inhand-turn") == 0
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local c = Fk:cloneCard("slash")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
}
Fk:addSkill(ciheng_viewas)
ciheng:addRelatedSkill(ciheng_delay)
ciheng:addRelatedSkill(ciheng_filter)
ciheng:addRelatedSkill(ciheng_prohibit)
dongmindonghuang:addSkill(ciheng)
Fk:loadTranslationTable{
  ["steam__dongmindonghuang"] = "董旻董璜",
  ["#steam__dongmindonghuang"] = "魔鲠",
  ["illustrator:steam__dongmindonghuang"] = "北★MAN",
  ["designer:steam__dongmindonghuang"] = "小叶子",

  ["steam__ciheng"] = "呲横",
  [":steam__ciheng"] = "出牌阶段开始时，你可选择两名角色，本回合你仅能对这些角色使用牌，并令这些角色选择其任意张手牌，本回合这些牌视为【决斗】且"..
  "其余手牌可当【杀】使用或打出。此阶段结束时，这些角色弃置手牌中不为【决斗】的牌。",
  ["steam__ciheng&"] = "呲横",
  [":steam__ciheng&"] = "你可以将非“呲横”手牌当【杀】使用或打出。",
  ["#steam__ciheng-choose"] = "呲横：你可以选择两名角色，本回合仅能对这些角色使用牌",
  ["@@steam__ciheng-turn"] = "呲横",
  ["#steam__ciheng-ask"] = "呲横：选择任意张手牌本回合视为【决斗】，其他手牌本回合可以当【杀】",
  ["@@steam__ciheng-inhand-turn"] = "呲横",
  ["#steam__ciheng_delay"] = "呲横",
  ["#steam__ciheng_filter"] = "呲横",
  ["#steam__ciheng&"] = "呲横：你可以将非“呲横”手牌当【杀】使用或打出",
}

local guanyinping = General(extension, "steam__guanyinping", "shu", 3, 3, General.Female)

local zhuiyue = fk.CreateViewAsSkill{
  name = "steam__zhuiyue",
  anim_type = "offensive",
  pattern = ".|.|.|.|analeptic,fire_attack,fire__slash",
  prompt = function (self, selected_cards, selected)
    local names = {"analeptic", "fire_attack", "fire__slash"}
    local index = RUtil.getSwitchState(Self, self.name)
    return "#steam__zhuiyue:::"..names[index]
  end,
  card_filter = function (self, to_select, selected, player)
    return #selected == 0
  end,
  view_as = function(self, cards, player)
    if #cards ~= 1 then return end
    local names = {"analeptic", "fire_attack", "fire__slash"}
    local index = RUtil.getSwitchState(player, self.name)
    local card = Fk:cloneCard(names[index])
    card.skillName = self.name
    card:addSubcard(cards[1])
    return card
  end,
  before_use = function (self, player, use)
    RUtil.changeSwitchState(player, self.name)
  end,
  enabled_at_response = function (self, player, response)
    if response then return end
    local names = {"analeptic", "fire_attack", "fire__slash"}
    local index = RUtil.getSwitchState(player, self.name)
    local card = Fk:cloneCard(names[index])
    card.skillName = self.name
    return (Fk.currentResponsePattern == nil and player:canUse(card)) or
      (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card))
  end,

  on_acquire = function (self, player)
    RUtil.setSwitchState(player, self.name, 1, 3)
  end,
  on_lose = function (self, player)
    RUtil.removeSwitchSkill(player, self.name)
  end,
}
local zhuiyue_trigger = fk.CreateTriggerSkill{
  name = "#steam__zhuiyue_trigger",
  mute = true,
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return target == player and table.contains(data.card.skillNames, zhuiyue.name)
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    for _, pid in ipairs(TargetGroup:getRealTargets(data.tos)) do
      local p = room:getPlayerById(pid)
      if not p.dead and not p.chained then
        p:setChainState(true)
      end
    end
  end,

  refresh_events = {fk.ChainStateChanged, fk.AfterCardTargetDeclared},
  can_refresh = function(self, event, target, player, data)
    if event == fk.ChainStateChanged then
      return player:hasSkill(zhuiyue) and not target.chained and not target.dead
    elseif event == fk.AfterCardTargetDeclared then
      return target == player and
        table.find(player:getTableMark("steam__zhuiyue"), function (id)
          return table.contains(TargetGroup:getRealTargets(data.tos), id)
        end)
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.ChainStateChanged then
      room:addTableMark(player, "steam__zhuiyue", target.id)
    elseif event == fk.AfterCardTargetDeclared then
      local mark = player:getTableMark("steam__zhuiyue")
      for i = #mark, 1, -1 do
        if table.contains(TargetGroup:getRealTargets(data.tos), mark[i]) then
          table.remove(mark, i)
        end
      end
      room:setPlayerMark(player, "steam__zhuiyue", mark)
      if not data.extraUse then
        player:addCardUseHistory(data.card.trueName, -1)
        data.extraUse = true
      end
    end
  end,
}
local zhuiyue_targetmod = fk.CreateTargetModSkill{
  name = "#steam__zhuiyue_targetmod",
  bypass_distances = function (self, player, skill, card, to)
    return card and table.contains(player:getTableMark("steam__zhuiyue"), to.id)
  end,
  bypass_times = function (self, player, skill, scope, card, to)
    return card and table.contains(player:getTableMark("steam__zhuiyue"), to.id)
  end,
}
local zhuohun = fk.CreateTriggerSkill{
  name = "steam__zhuohun",
  mute = true,
  events = {fk.Damage, fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      self.cost_data = nil
      for i = 1, 2, 1 do
        local events = player.room.logic:getActualDamageEvents(i, function(e)
          if event == fk.Damage then
            return e.data[1].from == player
          elseif event == fk.Damaged then
            return e.data[1].to == player
          end
        end, Player.HistoryTurn)
        if #events == i and events[i].data[1] == data then
          if i == 1 and table.find(player:getCardIds("h"), function (id)
            return not player:prohibitDiscard(id)
          end) then
            self.cost_data = 1
          elseif i == 2 and player.hp > 0 then
            self.cost_data = 2
          end
        end
      end
      return self.cost_data ~= nil
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#steam__zhuohun"..self.cost_data.."-invoke")
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    if self.cost_data == 1 then
      room:notifySkillInvoked(player, self.name, "drawcard")
      player:throwAllCards("h")
      if not player.dead then
        player:drawCards(3, self.name)
      end
    elseif self.cost_data == 2 then
      room:notifySkillInvoked(player, self.name, "support")
      room:loseHp(player, player.hp, self.name)
      if player:isWounded() and not player.dead then
        room:recover{
          who = player,
          num = player.maxHp - player.hp,
          recoverBy = player,
          skillName = self.name,
        }
      end
    end
  end,
}
zhuiyue:addRelatedSkill(zhuiyue_trigger)
zhuiyue:addRelatedSkill(zhuiyue_targetmod)
guanyinping:addSkill(zhuiyue)
guanyinping:addSkill(zhuohun)
Fk:loadTranslationTable{
  ["steam__guanyinping"] = "关银屏",
  ["#steam__guanyinping"] = "九天凰舞",
  ["illustrator:steam__guanyinping"] = "木美人",
  ["designer:steam__guanyinping"] = "末页&屑",

  ["steam__zhuiyue"] = "追月",
  [":steam__zhuiyue"] = "转换技，你可以将一张牌当①【酒】②【火攻】③火【杀】使用，并横置此牌的目标；一名角色重置后，你以其为目标的下一张牌无距离次数限制。",
  ["#steam__zhuiyue"] = "追月：你可以将一张牌当【%arg】使用，并横置此牌目标",
  ["#steam__zhuiyue_trigger"] = "追月",

  ["steam__zhuohun"] = "灼魂",
  [":steam__zhuohun"] = "你每回合首次造成或受到伤害后，可以弃置所有手牌并摸三张牌；再次造成或受到伤害后，可以失去所有体力并将体力回复至上限。",

  ["#steam__zhuohun1-invoke"] = "灼魂：是否弃置所有手牌，然后摸三张牌？",
  ["#steam__zhuohun2-invoke"] = "灼魂：是否失去所有体力，然后回复体力至上限？",

  ["$steam__zhuiyue1"] = "就用你的性命，一雪前耻。",
  ["$steam__zhuiyue2"] = "雪耻旧恨，今日清算。",
  ["$steam__zhuohun1"] = "父亲的武艺，我已掌握大半。",
  ["$steam__zhuohun2"] = "有青龙偃月刀在，小女必胜。",
  ["~steam__guanyinping"] = "红已花残，此仇，未能报。",
}

local yanghuiyu = General(extension, "steam__yanghuiyu", "jin", 3, 3, General.Female)
local shenyi = fk.CreateTriggerSkill{
  name = "steam__shenyi",
  anim_type = "support",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 then
      local dat = nil
      player.room.logic:getEventsByRule(GameEvent.UseCard, 1, function (e)
        if e.id ~= player.room.logic:getCurrentEvent().id then
          local use = e.data[1]
          dat = use
          return true
        end
      end, 1)
      return dat and dat.from ~= player.id
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local n = #room.logic:getEventsOfScope(GameEvent.UseCard, 5, Util.TrueFunc, Player.HistoryTurn)
    local cards = room:getNCards(n)
    local red = table.filter(cards, function (id)
      return Fk:getCardById(id).color == Card.Red
    end)
    if #red > 0 then
      room:askForYiji(player, red, room.alive_players, self.name, 0, n, "#steam__shenyi-give", cards)
    end
    cards = table.filter(cards, function (id)
      return table.contains(room.draw_pile, id)
    end)
    if #cards > 0 and not player.dead then
      room:askForGuanxing(player, cards)
    end
  end,
}
local hongcao = fk.CreateViewAsSkill{
  name = "steam__hongcao",
  anim_type = "support",
  pattern = "peach,nullification",
  prompt = function (self)
    local red = table.filter(Self:getCardIds("h"), function(id)
      return Fk:getCardById(id).color == Card.Red
    end)
    local black = table.filter(Self:getCardIds("h"), function(id)
      return Fk:getCardById(id).color == Card.Black
    end)
    if #red > #black then
      return "#steam__hongcao-peach"
    else
      return "#steam__hongcao-nullification"
    end
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    local red = table.filter(Self:getCardIds("h"), function(id)
      return Fk:getCardById(id).color == Card.Red
    end)
    local black = table.filter(Self:getCardIds("h"), function(id)
      return Fk:getCardById(id).color == Card.Black
    end)
    local c = Fk:cloneCard(#red > #black and "peach" or "nullification")
    c.skillName = self.name
    return c
  end,
  before_use = function (self, player, use)
    local room = player.room
    local red = table.filter(player:getCardIds("h"), function(id)
      return Fk:getCardById(id).color == Card.Red
    end)
    local black = table.filter(player:getCardIds("h"), function(id)
      return Fk:getCardById(id).color == Card.Black
    end)
    if use.card.name == "peach" then
      room:recastCard(red, player, self.name)
    else
      room:throwCard(black, self.name, player, player)
    end
  end,
  enabled_at_play = function (self, player)
    local red = table.filter(player:getCardIds("h"), function(id)
      return Fk:getCardById(id).color == Card.Red
    end)
    local black = table.filter(player:getCardIds("h"), function(id)
      return Fk:getCardById(id).color == Card.Black
    end)
    return #red > #black and player:canUse(Fk:cloneCard("peach"))
  end,
  enabled_at_response = function(self, player, response)
    if response or player:isKongcheng() then return end
    local red = table.filter(player:getCardIds("h"), function(id)
      return Fk:getCardById(id).color == Card.Red
    end)
    local black = table.filter(player:getCardIds("h"), function(id)
      return Fk:getCardById(id).color == Card.Black
    end)
    if #red > #black then
      return #U.getViewAsCardNames(player, self.name, {"peach"}) > 0
    elseif table.every(black, function (id)
      return not player:prohibitDiscard(id)
    end) then
      return #U.getViewAsCardNames(player, self.name, {"nullification"}) > 0
    end
  end,
}
yanghuiyu:addSkill(shenyi)
yanghuiyu:addSkill(hongcao)
Fk:loadTranslationTable{
  ["steam__yanghuiyu"] = "羊徽瑜",
  ["#steam__yanghuiyu"] = "端清才德",
  ["illustrator:steam__yanghuiyu"] = "匠人绘",
  ["designer:steam__yanghuiyu"] = "末页",

  ["steam__shenyi"] = "慎仪",
  [":steam__shenyi"] = "每回合限一次，你使用牌结算完毕后，若上一张牌不为你使用，你可以卜算X并分配其中的红色牌（X为本回合所有角色使用的牌数之和且"..
  "至多为5）。",
  ["steam__hongcao"] = "弘操",
  [":steam__hongcao"] = "若你手牌中：红色牌更多，你可以重铸所有红色手牌以视为使用【桃】；否则你可以弃置所有黑色手牌以视为使用【无懈可击】。",
  ["#steam__shenyi-give"] = "慎仪：你可以分配其中的红色牌",
  ["#steam__hongcao-peach"] = "弘操：你可以重铸所有红色手牌，视为使用【桃】",
  ["#steam__hongcao-nullification"] = "弘操：你可以弃置所有黑色手牌，视为使用【无懈可击】",

  ["$steam__shenyi1"] = "贤良淑德，才学洽闻。",
  ["$steam__shenyi2"] = "聪慧贤德，以文才称。",
  ["$steam__hongcao1"] = "终温且惠，其仪淑慎。",
  ["$steam__hongcao2"] = "既慎其仪，克明礼教。",
  ["~steam__yanghuiyu"] = "心之云痛，痛贯穹昊……",
}

--[[
local zhaoe = General(extension, "steam__zhaoe", "qun", 4, 4, General.Female)

local steam__renchou = fk.CreateViewAsSkill{
  name = "steam__renchou",
  anim_type = "offensive",
  pattern = "duel",
  prompt = function(self)
    local promot = "#steam__renchou"
    local x = Self:getMark("steam__renchou-turn")
    if x > 0 then
      promot = "#steam__renchou-ex:::"..(x+1)
    end
    return promot
  end,
  card_filter = function(self, to_select, selected)
    return true
  end,
  view_as = function(self, cards)
    if #cards == 0 or #cards <= Self:getMark("steam__renchou-turn")  then return nil end
    local c = Fk:cloneCard("duel")
    c.skillName = self.name
    c:addSubcards(cards)
    return c
  end,
  before_use = function(self, player, use)
    local room = player.room
    local x = #use.card.subcards
    room:setPlayerMark(player, "steam__renchou-turn", x)
    use.additionalDamage = (x - 1)
  end,
  after_use = function (self, player, use)
    if player:getMark("@@steam__yanshi") ~= 0 then
      local room = player.room
      room:setPlayerMark(player, "@@steam__yanshi", 0)
      room:handleAddLoseSkills(player, "-steam__renchou")
    end
  end,
  enabled_at_play = function(self, player)
    return true
  end,
  enabled_at_response = function (self, player, response)
    return not response
  end,

  on_lose = function (self, player)
    if player:getMark("@@steam__yanshi") ~= 0 then
      player.room:setPlayerMark(player, "@@steam__yanshi", 0)
    end
  end,
}

local steam__renchou_trigger = fk.CreateTriggerSkill{
  name = "#steam__renchou_trigger",
  events = {fk.CardUsing},
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(steam__renchou) and table.contains(data.card.skillNames, steam__renchou.name)
      and player.hp == 1 then
      return #player.room.logic:getEventsOfScope(GameEvent.Death, 1, function(e)
        local death = e.data[1]
        return death.damage and death.damage.from == player
      end, Player.HistoryTurn) > 0
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    player:drawCards(1, "steam__renchou")
  end,
}
steam__renchou:addRelatedSkill(steam__renchou_trigger)

zhaoe:addSkill(steam__renchou)

local steam__yanshi = fk.CreateTriggerSkill{
  name = "steam__yanshi",
  events = {fk.EnterDying},
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player and player.hp < 1 then
      return table.find(player.room.alive_players, function (p)
        return not p:hasSkill(steam__renchou, true)
      end) ~= nil
    end
  end,
  on_cost = function (self, event, target, player, data)
    local targets = table.filter(player.room.alive_players, function (p) return not p:hasSkill(steam__renchou, true) end)
    local tos = player.room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1,
    "#steam__yanshi-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    room:setPlayerMark(to, "@@steam__yanshi", 1)
    room:handleAddLoseSkills(to, "steam__renchou")
    if not player.dead then
      room:recover { num = 1-player.hp, skillName = self.name, who = player, recoverBy = player }
    end
  end,
}
zhaoe:addSkill(steam__yanshi)
Fk:loadTranslationTable{
  ["steam__zhaoe"] = "赵娥",
  ["#steam__zhaoe"] = "",
  ["illustrator:steam__zhaoe"] = "哥达耀",
  ["designer:steam__zhaoe"] = "从珂",

  ["steam__renchou"] = "刃仇",
  [":steam__renchou"] = "你可以将任意张牌当一张伤害基数为底牌数的【决斗】使用（须至少比本回合上次发动多1张）；你杀死角色的回合内，此【决斗】带有《残躯→摸一张牌》。",
  ["#steam__renchou"] = "刃仇：将任意张牌当害基数为底牌数的【决斗】使用",
  ["#steam__renchou-ex"] = "刃仇：将至少%arg张牌当害基数为底牌数的【决斗】使用",
  ["#steam__renchou_trigger"] = "刃仇",

  ["steam__yanshi"] = "言誓",
  [":steam__yanshi"] = "当你进入濒死状态时，你可以令一名没有“刃仇”的角色获得发动后失去的“刃仇”，然后你回复体力至1点。",
  ["#steam__yanshi-choose"] = "言誓：你可令一名没有“刃仇”的角色获得发动后失去的“刃仇”，回复体力至1",
  ["@@steam__yanshi"] = "言誓:刃仇",
}
--]]


-- S钟会
local szhonghui = General(extension, "steam__szhonghui", "wei", 3, 4)
szhonghui.hidden = true
Fk:loadTranslationTable{
  ["steam__szhonghui"] = "<font color='#FF83FA'>S</font>钟会", -- 粉色
  ["#steam__szhonghui"] = "吞象之蛇",
  ["cv:steam__szhonghui"] = "官方",
  ["illustrator:steam__szhonghui"] = "官方",
  ["designer:steam__szhonghui"] = "Sachiko&玄蝶既白",
  ["~steam__szhonghui"] = "这就是……自食恶果的下场吗？",
}

local yuzhi = fk.CreateTriggerSkill{
  name = "steam__yuzhi",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.RoundEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    local round = room:getBanner("RoundCount") or 0
    local n = #room.logic:getEventsOfScope(GameEvent.UseCard, round, function(e)
      local use = e.data[1]
      return use.from == player.id
    end, Player.HistoryRound)
    if n >= round then
      room:notifySkillInvoked(player, self.name, "drawcard")
      player:drawCards(round, self.name)
    else
      room:damage{
        to = player,
        damage = 1,
        damageType = fk.ThunderDamage,
        skillName = self.name,
      }
    end
  end,
}
szhonghui:addSkill(yuzhi)
Fk:loadTranslationTable{
  ["steam__yuzhi"] = "迂志",
  [":steam__yuzhi"] = "锁定技。轮次结束时，若你本轮使用的牌数不小于X，则你摸X张牌（X为游戏轮数），否则你受到1点雷电伤害。",

  ["$steam__yuzhi1"] = "汉鹿已失，魏牛犹在，吾欲执其耳。",
  ["$steam__yuzhi2"] = "我欲行夏禹旧事，为天下人。",
  ["$steam__yuzhi3"] = "人生艰难，如逆水行舟，不欲进则必退。",
  ["$steam__yuzhi4"] = "蛇可吞象，我钟会亦可吞天食地！",
}

local xieshu = fk.CreateTriggerSkill{
  name = "steam__xieshu",
  anim_type = "drawcard",
  events = {fk.Damage, fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and #player:getCardIds("he") >= player.hp and player.hp > 0
  end,
  on_cost = function(self, event, target, player, data)
    local x, x2 = player.hp, player:getLostHp()
    local cards = player.room:askForDiscard(player, x, x, true, self.name, true, ".", "#steam__xieshu-card:::"..x..":"..x2, true)
    if #cards == x then
      self.cost_data = {cards = cards}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(self.cost_data.cards, self.name, player, player)
    if not player.dead then
      player:drawCards(player:getLostHp(), self.name)
    end
  end,

  -- 究极取巧
  refresh_events = {fk.AfterDying},
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(self) and not target.dead
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:invalidateSkill(player, self.name, "-turn")
  end,
}
szhonghui:addSkill(xieshu)

Fk:loadTranslationTable{
  ["steam__xieshu"] = "挟术",
  [":steam__xieshu"] = "当你造成或受到伤害后，若本回合没有角色脱离过濒死状态，则你可以弃置体力值张牌并摸已损失体力值张牌。",
  ["#steam__xieshu-card"] = "挟术：你可以弃置 %arg 张牌，摸 %arg2 张牌",

  ["$steam__xieshu1"] = "今长缨在手，欲问鼎九州。",
  ["$steam__xieshu2"] = "我有佐国之术，可缚苍龙。",
  ["$steam__xieshu3"] = "不为刀下脍，且做俎上刀。",
}

local steam__fulong = fk.CreateTriggerSkill{
  name = "steam__fulong",
  frequency = Skill.Limited,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and player.hp == 1
    and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#steam__fulong")
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getAlivePlayers()) do
      if not p.dead and not p.chained then
        p:setChainState(true)
      end
    end
    if player.dead then return end
    room:setPlayerMark(player, "@@steam__fulong-turn", 1)
  end,

  refresh_events = {fk.CardUsing},
  can_refresh = function(self, event, target, player, data)
    return player == target and player:getMark("@@steam__fulong-turn") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    data.disresponsiveList = data.disresponsiveList or {}
    for _, pid in ipairs(TargetGroup:getRealTargets(data.tos)) do
      if room:getPlayerById(pid).chained then
        table.insertIfNeed(data.disresponsiveList, pid)
      end
    end
  end,
}

local steam__fulong_targetmod = fk.CreateTargetModSkill{
  name = "#steam__fulong_targetmod",
  bypass_times = function(self, player, skill, scope, card, to)
    return card and player and to and player:getMark("@@steam__fulong-turn") ~= 0 and to.chained
  end,
}
steam__fulong:addRelatedSkill(steam__fulong_targetmod)

szhonghui:addSkill(steam__fulong)

Fk:loadTranslationTable{
  ["steam__fulong"] = "缚龙",
  [":steam__fulong"] = "限定技。出牌阶段开始时，若你的体力值为1，则你可以横置所有角色。然后直到本回合结束：你对处于连环状态的角色使用牌无次数限制，处于连环状态的角色无法响应你使用的牌。",
  ["@@steam__fulong-turn"] = "缚龙",
  ["#steam__fulong"] = "缚龙：你可横置所有角色，对横置角色使用牌无次数限制且无法响应",

  ["$steam__fulong1"] = "吾为王者，何居人下！",
  ["$steam__fulong2"] = "金鳞，岂是池中之物？",
}

-- 谋钟会
local mouzhonghui = General(extension, "steam__mouzhonghui", "wei", 4)
Fk:loadTranslationTable{
  ["steam__mouzhonghui"] = "<font color='#33EE00'>谋</font>钟会", -- 绿色
  ["#steam__mouzhonghui"] = "精炼策数",
  ["cv:steam__mouzhonghui"] = "官方",
  ["illustrator:steam__mouzhonghui"] = "官方",
  ["designer:steam__mouzhonghui"] = "Sachiko",
  ["~steam__mouzhonghui"] = "不学陶朱法，游魂归故乡！",
}

local newForesightSkill = fk.CreateActiveSkill{
  name = "steam__juemou__foresight_skill",
  mod_target_filter = Util.TrueFunc,
  can_use = function(self, player, card)
    return not player:isProhibited(player, card)
  end,
  on_use = function(self, room, cardUseEvent)
    if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
      cardUseEvent.tos = {{cardUseEvent.from}}
    end
  end,
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    room:askForGuanxing(to, room:getNCards(4), nil, nil)
    room:drawCards(to, 4, self.name)
  end
}
newForesightSkill.cardSkill = true
Fk:addSkill(newForesightSkill)

local steam__juemou = fk.CreateViewAsSkill{
  name = "steam__juemou",
  switch_skill_name = "steam__juemou",
  pattern = "foresight,enemy_at_the_gates",
  prompt = function (self)
    return "#steam__juemou-"..Self:getSwitchSkillState(self.name, false, true)
  end,
  card_filter = function(self, to_select, selected)
    local card = Fk:getCardById(to_select)
    if card.color == Card.NoColor then return false end
    if #selected == 1 then
      return card.color ~= Fk:getCardById(selected[1]).color
    else
      return #selected == 0
    end
  end,
  view_as = function(self, cards)
    if #cards ~= 2 then return nil end
    local name = (Self:getSwitchSkillState(self.name) == fk.SwitchYin) and "hanqing__enemy_at_the_gates" or "foresight"
    local c = Fk:cloneCard(name)
    if name == "foresight" then
      -- 修改虚拟牌的skill应该没问题吧
      c.skill = newForesightSkill
    end
    c.skillName = self.name
    c:addSubcards(cards)
    return c
  end,
  before_use = function(self, player, use)
    if use.card.name == "hanqing__enemy_at_the_gates" then
      use.extra_data = use.extra_data or {}
      use.extra_data.fromArea = "bottom"
      use.extra_data.toArea = "bottom"
    end
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  enabled_at_response = Util.FalseFunc,
}
mouzhonghui:addSkill(steam__juemou)

Fk:loadTranslationTable{
  ["steam__juemou"] = "谲谋",
  [":steam__juemou"] = "转换技。出牌阶段限一次，你可以将两张异色牌当做一张{阳：牌面数值翻倍的【洞烛先机】；阴：从牌堆底展示牌的【兵临城下】}使用。",
  -- 出牌阶段，对一名其他角色使用。你展示牌堆底的四张牌，依次对目标角色使用其中的【杀】，然后将其余的牌以原顺序放回牌堆底。
  ["#steam__juemou-yin"] = "谲谋:将两张异色牌当一张从牌堆底展示牌的【兵临城下】使用",
  ["#steam__juemou-yang"] = "谲谋:将两张异色牌当一张牌面数值翻倍的【洞烛先机】使用",
  ["steam__juemou__foresight_skill"] = "洞烛先机",

  ["$steam__juemou1"] = "算无遗策，晋道克昌，皆吾之力也！",
  ["$steam__juemou2"] = "精练策数，料敌制胜！",
}

local steam__cuanmo = fk.CreateTriggerSkill{
  name = "steam__cuanmo",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if target ~= player and player:hasSkill(self) then
      return true
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local info = {}
    room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
      local use = e.data[1]
      if use.from == target.id and use.card.suit ~= Card.NoSuit and not use.card.is_passive
        and (use.card.type == Card.TypeBasic or use.card:isCommonTrick()) then
        info[use.card.name] = info[use.card.name] or {}
        table.insertIfNeed(info[use.card.name], use.card:getSuitString(true))
      end
    end, Player.HistoryTurn)
    if next(info) ~= nil then
      local success, dat = room:askForUseViewAsSkill(player, "steam__cuanmo_viewas",
      "#steam__cuanmo-ask", true,
      {steam__cuanmo_info = info})
      if success and dat then
        self.cost_data = {use = {name = dat.interaction:split(":")[4], cards = dat.cards, tos = dat.targets}}
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local dat = self.cost_data.use
    local card = Fk:cloneCard(dat.name)
    card:addSubcard(dat.cards[1])
    card.skillName = self.name
    local use = {
      from = player.id,
      tos = table.map(dat.tos, function(p) return {p} end),
      card = card,
      extraUse = true,
    }
    room:useCard(use)
    if not player.dead and not target.dead and table.contains(TargetGroup:getRealTargets(use.tos), target.id) then
      room:addTableMark(target, "@@steam__cuanmo", {use.card.trueName, player.id})
    end
  end,
}

--- 将字符串型花色表翻译后组合成一个字符串
local suitsToStr = function (suits)
  return table.concat(table.map(suits, function(s) return Fk:translate(s) end), ",")
end

local steam__cuanmo_viewas = fk.CreateViewAsSkill{
  name = "steam__cuanmo_viewas",
  interaction = function(self)
    local all_choices, choices = {}, {}
    local info = self.steam__cuanmo_info
    if info == nil then return nil end
    for name, suits in pairs(info) do
      local str = "SteamNameWithSuit:::"..name..":"..suitsToStr(suits)
      table.insert(all_choices, str)
      local card = Fk:cloneCard(name)
      if Self:canUse(card, {bypass_distances = true, bypass_times = true}) and not Self:prohibitUse(card) then
        table.insert(choices, str)
      end
    end
    if #choices > 0 then
      return UI.ComboBox { choices = choices, all_choices = all_choices }
    end
  end,
  card_filter = function(self, to_select, selected)
    local nameStr, info = self.interaction.data, self.steam__cuanmo_info
    if nameStr == nil or info == nil then return false end
    local name = nameStr:split(":")[4]
    local suits = info[name] or {}
    return #selected == 0 and table.contains(suits, Fk:getCardById(to_select):getSuitString(true))
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return nil end
    local name = self.interaction.data:split(":")[4]
    local c = Fk:cloneCard(name)
    c.skillName = "steam__cuanmo"
    c:addSubcard(cards[1])
    if Self:prohibitUse(c) then return nil end
    return c
  end,
}
Fk:addSkill(steam__cuanmo_viewas)


local steam__cuanmo_delay = fk.CreateTriggerSkill{
  name = "#steam__cuanmo_delay",
  mute = true,
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if target ~= player then return false end
    local mark = player:getTableMark("@@steam__cuanmo")
    if #mark > 0 then
      return table.find(mark, function (v)
        return v[1] == data.card.trueName
      end)
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local owner, temp
    local mark = player:getTableMark("@@steam__cuanmo")
    for i = #mark, 1, -1 do
      local v = mark[i]
      if v[1] == data.card.trueName then
        if not owner then
          temp = room:getPlayerById(v[2])
          if not temp.dead then
            owner = temp
          end
        end
        table.remove(mark, i)
      end
    end
    room:setPlayerMark(target, "@@steam__cuanmo", #mark > 0 and mark or 0)
    if owner then
      owner:broadcastSkillInvoke("steam__cuanmo", 1)
      room:notifySkillInvoked(owner, "steam__cuanmo", "control")
      local targets = {}
      for _, p in ipairs(room.alive_players) do
        if not target:isProhibited(p, data.card) and data.card.skill:modTargetFilter(p.id, {}, target, data.card, false) then
          table.insert(targets, p.id)
        end
      end
      if #targets == 0 then return false end
      local choose_num = math.min(#targets, #TargetGroup:getRealTargets(data.tos))
      if choose_num == 0 then return false end
      local tos = room:askForChoosePlayers(owner, targets, 1, choose_num,
      "#steam__cuanmo-choose:"..target.id.."::"..data.card:toLogString(), self.name, false)
      if #tos > 0 then
        room:sortPlayersByAction(tos)
        data.tos = table.map(tos, function(p) return {p} end)
      end
    end
  end,
}
steam__cuanmo:addRelatedSkill(steam__cuanmo_delay)

mouzhonghui:addSkill(steam__cuanmo)

Fk:loadTranslationTable{
  ["steam__cuanmo"] = "篡墨",
  [":steam__cuanmo"] = "其他角色的回合结束时，你可以将一张牌当做其本回合使用过的基本牌或普通锦囊牌使用（须两者花色相同），若目标包含其，则其使用的下一张同名牌的目标由你指定。",
  ["steam__cuanmo_viewas"] = "篡墨",
  ["#steam__cuanmo-ask"] = "篡墨：先选视为使用的牌名，再选择一张与其同花色的牌",
  ["@@steam__cuanmo"] = "篡墨",
  ["#steam__cuanmo_delay"] = "篡墨",
  ["SteamNameWithSuit"] = "%arg[%arg2]",
  ["#steam__cuanmo-choose"] = "篡墨：请重新选择 %src 使用%arg的目标",

  ["$steam__cuanmo1"] = "蜀川三千里，皆由我一言决之。",
  ["$steam__cuanmo2"] = "顺我者封侯拜将，逆我者斧钺加身。",
}


-- 星钟会
local starzhonghui = General(extension, "steam__starzhonghui", "wei", 4)
starzhonghui.hidden = true
local starzhonghuiWin = fk.CreateActiveSkill{ name = "steam__starzhonghui_win_audio" }
starzhonghuiWin.package = extension
Fk:addSkill(starzhonghuiWin)
Fk:loadTranslationTable{
  ["steam__starzhonghui"] = "<font color='#FF7700'>星</font>钟会", -- 橙色
  ["#steam__starzhonghui"] = "欲壑难填",
  ["cv:steam__starzhonghui"] = "官方",
  ["illustrator:steam__starzhonghui"] = "官方",
  ["designer:steam__starzhonghui"] = "Sachiko",
  ["~steam__starzhonghui"] = "千里之愿，竟至于半途……",
  ["$steam__starzhonghui_win_audio"] = "虽已青史留名，尚有大事能为。",
}
local starzhonghui2 = General(extension, "steam2__starzhonghui", "wei", 4)
starzhonghui2.total_hidden = true
local starzhonghui2Win = fk.CreateActiveSkill{ name = "steam2__starzhonghui_win_audio" }
starzhonghui2Win.package = extension
Fk:addSkill(starzhonghui2Win)
Fk:loadTranslationTable{
  ["steam2__starzhonghui"] = "<font color='#FF7700'>星</font>钟会",
  ["#steam2__starzhonghui"] = "欲壑难填",
  ["cv:steam2__starzhonghui"] = "官方",
  ["illustrator:steam2__starzhonghui"] = "官方",
  ["designer:steam2__starzhonghui"] = "Sachiko",
  ["~steam2__starzhonghui"] = "千里之愿，竟至于半途……",
  ["$steam2__starzhonghui_win_audio"] = "夫英雄者自当如我这般，图则有获，谋则即成，哈哈哈哈！",
}

local steam__yewang = fk.CreateTriggerSkill{
  name = "steam__yewang",
  anim_type = "drawcard",
  events = {fk.BeforeDrawCard},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if player.room:getBanner("RoundCount") == nil then return end
    local x = math.min(player.room:getBanner("RoundCount") or 0, #player:getAvailableEquipSlots())
    if x == 0 then return end
    if player:hasSkill(self) and target == player then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    data.num = data.num + math.min(player.room:getBanner("RoundCount") or 0, #player:getAvailableEquipSlots())
  end,

  ---FIXME: 这个roomtag之后可能会被废弃
  refresh_events = {fk.RoundStart},
  can_refresh = function (self, event, target, player, data)
    local room = player.room
    return room:getBanner("RoundCount") ~= room:getBanner("RoundCount")
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    room:setBanner("RoundCount", room:getBanner("RoundCount"))
  end,
  on_acquire = function (self, player)
    local room = player.room
    room:setBanner("RoundCount", room:getBanner("RoundCount"))
  end,
}
local steam__yewang_maxcards = fk.CreateMaxCardsSkill{
  name = "#steam__yewang_maxcards",
  correct_func = function(self, player)
    if player:hasSkill(steam__yewang) then
      local maxNum = #player:getAvailableEquipSlots()
      return - math.min(Fk:currentRoom():getBanner("RoundCount") or 0, maxNum)
    end
  end,
}
steam__yewang:addRelatedSkill(steam__yewang_maxcards)
starzhonghui:addSkill(steam__yewang)
starzhonghui2:addSkill("steam__yewang")
Fk:loadTranslationTable{
  ["steam__yewang"] = "野望",
  [":steam__yewang"] = "锁定技，你的摸牌数+X，手牌上限-X（X为游戏轮数且至多为你未废除的空置装备栏数）。",
  ["$steam__yewang1"] = "蟒行轻进，不如缓进徐图。",
  ["$steam__yewang2"] = "吾画无遗策，何须忧患小错？",
}

local steam__zhuyuan = fk.CreateTriggerSkill{
  name = "steam__zhuyuan",
  anim_type = "offensive",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self, true) and player:isKongcheng() and player:usedSkillTimes(self.name) == 0
    and player:getMark("steam__zhuyuan_triggered-turn") == 0 then
      for _, move in ipairs(data) do
        if move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand then
              return true
            end
          end
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    -- 用于判断是否被触发过
    player.room:setPlayerMark(player, "steam__zhuyuan_triggered-turn", 1)
    if #player:getAvailableEquipSlots() == 0 or not player:hasSkill(self) then return false end
    return player:getMark("steam__zhuyuan_must") ~= 0 or player.room:askForSkillInvoke(player, self.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local slots = player:getAvailableEquipSlots()
    if #slots == 0 then return end
    local slot = room:askForChoice(player, slots, self.name, "#steam__zhuyuan-abort")
    room:abortPlayerArea(player, slot)
    if player.dead then return end
    player:drawCards(0, self.name) -- 危险的操作
    if player.dead then return end
    if player:getMark("@@steam__zhuyuan-turn") == 0 then
      room:setPlayerMark(player, "@@steam__zhuyuan-turn", 1)
      -- 预支额定回合的次数可叠加
      player:gainAnExtraTurn(true, self.name)
    end
    if not player.dead and player.tag["steam__zhuyuan_invoked"] == nil then
      player.tag["steam__zhuyuan_invoked"] = true -- 请勿调用mark和usedtimes，都可能被修改

      local deputy = false
      if player.general == "steam__starzhonghui" then
        room:setPlayerProperty(player, "general", "steam2__starzhonghui")
      elseif player.deputyGeneral == "steam__starzhonghui" then
        deputy = true
        room:setPlayerProperty(player, "deputyGeneral", "steam2__starzhonghui")
      end
      room:doAnimate("InvokeUltSkill", {
        name = self.name,
        player = player.id,
        deputy = deputy,
      })
      room:delay(2000)

      room:setPlayerMark(player, "@@steam__zhuyuan_recover", 1)
      room:setPlayerMark(player, "steam__zhuyuan_must", 1)
    end
  end,

  refresh_events = {fk.TurnEnd},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@@steam__zhuyuan-turn") ~= 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:addPlayerMark(player, "@steam__zhuyuan_preturn", 1)
  end,
}
local steam__zhuyuan_delay = fk.CreateTriggerSkill{
  name = "#steam__zhuyuan_delay",
  mute = true,
  events = {fk.BeforeTurnStart, fk.PreHpRecover},
  can_trigger = function(self, event, target, player, data)
    if target == player then
      if event == fk.BeforeTurnStart then
        ---FIXEME: 此时机的额定回合判断方法可能会修改
        return player:getCurrentExtraTurnReason() == "game_rule" and player:getMark("@steam__zhuyuan_preturn") > 0
      else
        return player:getMark("@@steam__zhuyuan_recover") ~= 0
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:notifySkillInvoked(player, "steam__zhuyuan", "negative")
    if event == fk.BeforeTurnStart then
      player.room:removePlayerMark(player, "@steam__zhuyuan_preturn")
    end
    return true
  end,

  refresh_events = {fk.Deathed},
  can_refresh = function (self, event, target, player, data)
    return data.damage and data.damage.from == player
  end,
  on_refresh = function (self, event, target, player, data)
    if player:getMark("@@steam__zhuyuan_recover") ~= 0 then
      player.room:setPlayerMark(player, "@@steam__zhuyuan_recover", 0)
    end
    if string.find(player.general, "starzhonghui") or string.find(player.deputyGeneral, "starzhonghui") then
      player.room:delay(700) -- 避免与死者阵亡语音重叠
      player.room:broadcastPlaySound("./packages/"..extension.extensionName.."/audio/special/steam__zhuyuan_kill_audio")
    end
  end,
}
steam__zhuyuan:addRelatedSkill(steam__zhuyuan_delay)
starzhonghui:addSkill(steam__zhuyuan)
starzhonghui2:addSkill("steam__zhuyuan")
Fk:loadTranslationTable{
  ["steam__zhuyuan"] = "逐渊",
  [":steam__zhuyuan"] = "当你每回合首次失去所有手牌时，你可以废除一个装备栏并摸零张牌，然后你于本回合结束后提前执行你以后的下一个额定回合。当你首次发动此技能后，你无法回复体力直到杀死角色，此技能改为“锁定技”。",
  ["#steam__zhuyuan"] = "逐渊：你可以废除一个装备栏并摸0张牌，本回合结束后提前执行下一个额定回合",
  ["@steam__zhuyuan_preturn"] = "逐渊:预支", -- 用于表示将跳过下N个额定回合
  ["@@steam__zhuyuan_recover"] = "逐渊:无法回血",
  ["@@steam__zhuyuan-turn"] = "逐渊:发动", -- 由于表示此回合结束后会进行额外回合
  ["#steam__zhuyuan_delay"] = "逐渊",
  ["#steam__zhuyuan-abort"] = "逐渊：请废除1个装备栏",
  ["$steam__zhuyuan1"] = "哼，司马氏可为，吾如何不可为？",
  ["$steam__zhuyuan2"] = "这天下，未必不能姓钟！",
  -- 杀死角色：天下唾手可得，岂容宵小妄为？
}


-- 往钟会
local wangzhonghui = General(extension, "steam__wangzhonghui", "wei", 4)
wangzhonghui.hidden = true
Fk:loadTranslationTable{
  ["steam__wangzhonghui"] = "<font color='#FFB6C6'>往</font>钟会", -- 浅粉色
  ["#steam__wangzhonghui"] = "纵恣挥军",
  ["cv:steam__wangzhonghui"] = "官方",
  ["illustrator:steam__wangzhonghui"] = "官方",
  ["designer:steam__wangzhonghui"] = "Sachiko",
  ["~steam__wangzhonghui"] = "是谁……走漏了风声？",
}

local steam__zhenggong = fk.CreateTriggerSkill{
  name = "steam__zhenggong",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseChanging},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      local phase = data.to - 1
      if phase > 0 and phase < 7 then
        return phase <= player:getMark("@steam__zhenggong")
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if data.to ~= Player.Play then
      player.room:sendLog{
        type = "#PhaseChanged",
        from = player.id,
        arg = Util.PhaseStrMapper(data.to),
        arg2 = "phase_play",
      }
      data.to = Player.Play
    end
  end,

  refresh_events = {fk.AfterRoundEnd},
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(self, true)
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local num = 0
    room.logic:getActualDamageEvents(1, function(e)
      local damage = e.data[1]
      if damage.from == player then
        num = num + damage.damage
      end
      -- 打自己算两次
      if damage.to == player then
        num = num + damage.damage
      end
      return false
    end, Player.HistoryRound)
    room:setPlayerMark(player, "@steam__zhenggong", num)
  end,
  -- 狠狠的查记录
  on_acquire = function (self, player, is_start)
    local room = player.room
    local currentRound = room.logic:getCurrentEvent():findParent(GameEvent.Round)
    if not currentRound then return end
    local lastRound = room.logic:getEventsByRule(GameEvent.Round, 1, function (e)
      return e.id < currentRound.id
    end, 1)[1]
    if not lastRound then return end
    local num = 0
    room.logic:getActualDamageEvents(1, function(e)
      if e.id > currentRound.id then return false end
      local damage = e.data[1]
      if damage.from == player then
        num = num + damage.damage
      end
      if damage.to == player then
        num = num + damage.damage
      end
      return false
    end, nil, lastRound.id)
    room:setPlayerMark(player, "@steam__zhenggong", num)
  end,
  on_lose = function (self, player)
    player.room:setPlayerMark(player, "@steam__zhenggong", 0)
  end,
}
wangzhonghui:addSkill(steam__zhenggong)
Fk:loadTranslationTable{
  ["steam__zhenggong"] = "争功",
  [":steam__zhenggong"] = "锁定技，你回合内的前X个阶段开始前，你将此阶段改为出牌阶段（X为你上轮造成与受到的伤害之和）。",
  ["@steam__zhenggong"] = "争功",
}

local steam__jigou = fk.CreateActiveSkill{
  name = "steam__jigou",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "#steam__jigou",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    to:drawCards(2, self.name)
    if to:isAlive() and player:isAlive() and to:getHandcardNum() >= player:getHandcardNum() then
      local all_choices = {"steam__jigou_damage:"..player.id, "steam__jigou_move:"..player.id, "steam__jigou_give:"..player.id}
      local choices = {all_choices[1]}
      local cardsToMove = table.filter(to:getCardIds("ej"), function (id)
        return table.find(room.alive_players, function (p)
          return to:canMoveCardInBoardTo(p, id)
        end) ~= nil
      end)
      if #cardsToMove >= 2 then
        table.insert(choices, all_choices[2])
      end
      if #to:getCardIds("he") > 2 then
        table.insert(choices, all_choices[3])
      end
      local choice = room:askForChoice(to, choices, self.name, nil, false, all_choices)
      if choice == all_choices[2] then
        for _ = 1, 2 do
          local moveTars = table.filter(room.alive_players, function (p)
            return to:canMoveCardsInBoardTo(p)
          end)
          if #moveTars == 0 then break end
          local tos = room:askForChoosePlayers(player, table.map(moveTars, Util.IdMapper), 1, 1,
          "#steam__jigou-move:"..to.id, self.name, true) -- 可取消
          if #tos == 0 then break end
          local second = room:getPlayerById(tos[1])
          room:askForMoveCardInBoard(player, to, second, self.name, nil, to)
          if player.dead or to.dead then return end
        end
      elseif choice == all_choices[3] then
        local cards = room:askForCard(to, 3, 3, true, self.name, false, ".", "#steam__jigou-give:"..player.id)
        room:obtainCard(player, cards, false, fk.ReasonGive, to.id, self.name)
      else
        room:doIndicate(player.id, {to.id})
        room:damage { from = player, to = to, damage = 1, skillName = self.name }
      end
    end
  end,
}
wangzhonghui:addSkill(steam__jigou)

Fk:loadTranslationTable{
  ["steam__jigou"] = "惎构",
  [":steam__jigou"] = "出牌阶段限一次，你可以令一名其他角色摸两张牌，然后若其手牌数不小于你，其选择一项：1.受到你对其造成的1点伤害；2.你可移动其场上的2张牌；3.交给你3张牌。",
  ["#steam__jigou"] = "惎构：令一名其他角色摸两张牌，然后若其手牌数不小于你，其须选一项惩罚",
  ["steam__jigou_damage"] = "%src 对你造成1点伤害",
  ["steam__jigou_move"] = "%src 可移动你场上的2张牌",
  ["steam__jigou_give"] = "你须交给 %src 3张牌",
  ["#steam__jigou-give"] = "惎构：请选择3张牌交给%src",
  ["#steam__jigou-move"] = "惎构：请选择一名角色，将 %src 场上1张牌移动至其区域",
  ["$steam__jigou1"] = "党同伐异，决不姑息！",
  ["$steam__jigou2"] = "铲除异己，方可酣睡！",
  ["$steam__jigou3"] = "顺我者封侯拜将，逆我者斧钺加身。",
}

local steam__qingsuan = fk.CreateTriggerSkill{
  name = "steam__qingsuan",
  anim_type = "offensive",
  frequency = Skill.Limited,
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0 then
      return table.find(player.room.alive_players, function (p)
        return table.contains(player:getTableMark("steam__qingsuan_record"), p.id)
      end)
    end
  end,
  on_cost = function (self, event, target, player, data)
    local targets = table.filter(player.room.alive_players, function (p)
      return table.contains(player:getTableMark("steam__qingsuan_record"), p.id)
    end)
    if #targets == 0 then return false end
    local success = player.room:askForUseActiveSkill(player, "steam__qingsuan_active", "#steam__qingsuan-invoke", true)
    if success then
      self.cost_data = {tos = table.map(targets, Util.IdMapper)}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = table.map(self.cost_data.tos, Util.Id2PlayerMapper)---@type table<ServerPlayer>
    for _, to in ipairs(tos) do
      if not to.dead then
        room:damage { from = player, to = to, damage = 1, skillName = self.name }
        if player.dead then return end
        if not to:isNude() then
          local cid = room:askForCardChosen(player, to, "he", self.name)
          room:obtainCard(player, cid, false, fk.ReasonJustMove, player.id, self.name)
          if player.dead then return end
        end
      end
    end
    for _, to in ipairs(tos) do
      if not to.dead then
        room:setPlayerMark(to, "@@steam__qingsuan_tar-turn", player.id)
      end
    end
  end,

  refresh_events = {fk.Damaged},
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(self, true) and data.from and data.from ~= player and target == player
    and not table.contains(player:getTableMark("steam__qingsuan_record"), data.from.id)
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:addTableMark(player, "steam__qingsuan_record", data.from.id)
  end,
}
local steam__qingsuan_targetmod = fk.CreateTargetModSkill{
  name = "#steam__qingsuan_targetmod",
  bypass_times = function(self, player, skill, scope, card, to)
    return card and player and to and to:getMark("@@steam__qingsuan_tar-turn") == player.id
  end,
  bypass_distances = function(self, player, skill, card, to)
    return card and player and to and to:getMark("@@steam__qingsuan_tar-turn") == player.id
  end,
}
steam__qingsuan:addRelatedSkill(steam__qingsuan_targetmod)
wangzhonghui:addSkill(steam__qingsuan)

-- askforskillinvoke 没有targetTip，很坏
local steam__qingsuan_active = fk.CreateActiveSkill{
  name = "steam__qingsuan_active",
  card_num = 0,
  target_num = 0,
  card_filter = Util.FalseFunc,
  target_tip = function (self, to_select, selected, selected_cards, card, selectable, extra_data)
    local to = Fk:currentRoom():getPlayerById(to_select)
    if to and table.contains(Self:getTableMark("steam__qingsuan_record"), to.id) then
      return "steam__qingsuan_tar"
    end
  end,
}
Fk:addSkill(steam__qingsuan_active)

Fk:loadTranslationTable{
  ["steam__qingsuan"] = "清算",
  [":steam__qingsuan"] = "限定技，回合开始时，你可以对本局游戏所有对你造成过伤害的其他角色各造成1点伤害并获得其一张牌，然后你本回合对这些角色使用牌无距离和次数限制。",
  ["@@steam__qingsuan_tar-turn"] = "被清算",
  ["steam__qingsuan_active"] = "清算",
  ["#steam__qingsuan-invoke"] = "清算:对所有对你造成过伤害的其他角色各造成1点伤害并获得其一张牌，本回合对他们用牌无距离和次数限制",
  ["steam__qingsuan_tar"] = "可清算",
  ["$steam__qingsuan1"] = "我们该，算算旧账了！",
  ["$steam__qingsuan2"] = "昨日之仇，如芒在背！",
}

-- 来钟会
local laizhonghui = General(extension, "steam__laizhonghui", "shu", 4)
laizhonghui.hidden = true
local steam__chengren = fk.CreateActiveSkill{
  name = "steam__chengren",
  anim_type = "offensive",
  min_card_num = 1,
  target_num = 0,
  prompt = "#steam__chengren",
  card_filter = function(self, to_select, selected)
    return table.contains(Self.player_cards[Player.Hand], to_select)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isKongcheng()
    and table.find(Fk:currentRoom().alive_players, function (p)
      return p ~= player
    end) ~= nil
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local x = 0
    local cards = effect.cards
    for _, id in ipairs(cards) do
      x = x + RUtil.cardNameLen(id)
    end
    room:askForYiji(player, cards, room:getOtherPlayers(player, false), self.name, #cards, #cards)
    if player.dead then return end
    local all_choices = U.getAllCardNames("bt")
    local choices = table.filter(all_choices, function (name)
      local card = Fk:cloneCard(name)
      if RUtil.cardNameLen(card) > x then return false end
      card.skillName = self.name
      return player:canUse(card, {bypass_times = true}) and not player:prohibitUse(card)
    end)
    if #choices == 0 then return end
    U.askForUseVirtualCard(room, player, choices, nil, self.name, nil, false, true, false, true)
  end,
}
laizhonghui:addSkill(steam__chengren)

local steam__suishu = fk.CreateTriggerSkill{
  name = "steam__suishu",
  anim_type = "control",
  events = {fk.AfterCardsMove, fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if player.room:canMoveCardInBoard() == 0 then return false end
    if event == fk.AfterCardsMove then
      return data.extra_data and data.extra_data.hcnm_becomeEmpty and table.contains(data.extra_data.hcnm_becomeEmpty, player.id)
    else
      return target == player
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local tos = room:askForChooseToMoveCardInBoard(player, "#steam__suishu-move", self.name, true)
    if #tos ~= 0 then
      self.cost_data = { tos = tos }
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local tos = table.map(self.cost_data.tos, Util.Id2PlayerMapper)
    room:askForMoveCardInBoard(player, tos[1], tos[2], self.name)
    local from = tos[1]---@type ServerPlayer
    if from.dead then return end
    local x = #table.filter(from.equipSlots, function (slot)
      return from:getEquipment(Util.convertSubtypeAndEquipSlot(slot)) == nil
    end)
    x = from:getHandcardNum() - x
    if x > 0 then
      room:askForDiscard(from, x, x, false, self.name, false)
    elseif x < 0 then
      from:drawCards(-x, self.name)
    end
  end,
}
laizhonghui:addSkill(steam__suishu)

local steam__tongju = fk.CreateTriggerSkill{
  name = "steam__tongju$",
  anim_type = "offensive",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player and data.card.trueName == "slash" and data.firstTarget then
      return table.find(player.room.alive_players, function (p)
        return p ~= player and (p.kingdom == "shu" or p.kingdom == "wei")
      end) ~= nil
    end
  end,
  on_trigger = function (self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    local targets = table.filter(room:getOtherPlayers(player), function (p)
      return (p.kingdom == "shu" or p.kingdom == "wei")
    end)
    room:doIndicate(player.id, table.map(targets, Util.IdMapper))
    -- 小心魏武帝插结改势力
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if not player:hasSkill(self) then break end
      if p:isAlive() and not p:isKongcheng() and (p.kingdom == "shu" or p.kingdom == "wei") then
        self:doCost(event, p, player, data)
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local cards = player.room:askForCard(target, 1, 1, false, self.name, true, "jink", "#steam__tongju-card:"..player.id)
    if #cards > 0 then
      self.cost_data = {cards = cards }
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:recastCard(self.cost_data.cards, target, self.name)
    data.additionalEffect = (data.additionalEffect or 0) + 1
  end,
}
laizhonghui:addSkill(steam__tongju)

Fk:loadTranslationTable{
  -- 希望别有读取名字长度的设，不然露馅
  ["steam__laizhonghui"] = "<font color='#0596BE'>来</font>钟会", 
  ["#steam__laizhonghui"] = "潜蛟化龙",
  ["cv:steam__laizhonghui"] = "官方",
  ["illustrator:steam__laizhonghui"] = "官方",
  ["designer:steam__laizhonghui"] = "Sachiko",

  ["steam__chengren"] = "承仁",
  [":steam__chengren"] = "出牌阶段限一次，你可以分配任意张手牌，然后视为使用一张牌名字数不大于X的即时牌（X为你分配的牌名字数之和）。",
  ["#steam__chengren"] = "承仁:分配任意张手牌，然后视为使用一张牌名字数不大于X的即时牌（X为你分配的牌名字数之和）",

  ["steam__suishu"] = "绥术",
  [":steam__suishu"] = "当你受到伤害后或失去所有手牌后，你可以移动场上一张牌，然后令因此失去牌的角色将手牌数调整至其空置装备栏数。",
  ["#steam__suishu-move"] = "绥术:你可移动场上一张牌，令失去牌的角色将手牌数调整至其空置装备栏数",

  ["steam__tongju"] = "同举",
  [":steam__tongju"] = "主公技。当你使用【杀】指定第一个目标后，其他蜀或魏势力角色可以重铸一张【闪】，然后令此牌效果额外结算一次。",
  ["#steam__tongju-card"] = "同举：你可以重铸一张【闪】，令 %src 的【杀】额外结算一次",

  ["$steam__chengren1"] = "既已功高盖主，何妨冕服加身？",
  ["$steam__chengren2"] = "天下大事无常，钟某亦可为王。",
  ["$steam__suishu1"] = "王侯将相不在其种，而在其行。",
  ["$steam__suishu2"] = "心怀屠龙之术，何患手无长缨？",
  ["$steam__tongju1"] = "我既搏一世之功，亦求万世之名。",
  ["$steam__tongju2"] = "我一人筚路蓝缕，可保阖族千秋万代！",
  ["~steam__laizhonghui"] = "我有大功于国，尔等怎敢逾制！",
}

-- 梦钟会
local ifzhonghui = General(extension, "steam__ifzhonghui", "xia", 4)
Fk:loadTranslationTable{
  ["steam__ifzhonghui"] = "<font color='#3333FF'>梦</font>钟会", -- 深蓝色
  ["#steam__ifzhonghui"] = "吞天饕餮",
  ["cv:steam__ifzhonghui"] = "官方",
  ["illustrator:steam__ifzhonghui"] = "官方",
  ["designer:steam__ifzhonghui"] = "Sachiko",
  ["~steam__ifzhonghui"] = "尔等以下犯上，欲诛九族否？",
  ["xia"] = "夏",
}

local steam__wanghe = fk.CreateTriggerSkill{
  name = "steam__wanghe",
  frequency = Skill.Compulsory,
  anim_type = "drawcard",
  events = {fk.Damage, fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      -- 若你的手牌数不是唯一最多
      return table.find(player.room.alive_players, function (p)
        return p ~= player and p:getHandcardNum() >= player:getHandcardNum()
      end) ~= nil
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "@steam__wanghe", 1)
    local maxNum = 0
    for _, p in ipairs(room.alive_players) do
      maxNum = math.max(maxNum, p:getHandcardNum())
    end
    player:drawCards(maxNum + 1 - player:getHandcardNum(), self.name)
    if player.dead then return end
    local x = player:getMark("@steam__wanghe")
    if #room:askForDiscard(player, x, x, true, self.name, true, nil, "#steam__wanghe-discard:::"..x) == 0 then
      room:loseHp(player, 1, self.name)
    end
  end,

  refresh_events = {fk.EnterDying},
  can_refresh = function (self, event, target, player, data)
    return player:getMark("@steam__wanghe") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@steam__wanghe", 0)
  end,

  on_lose = function (self, player)
    player.room:setPlayerMark(player, "@steam__wanghe", 0)
  end,
}
ifzhonghui:addSkill(steam__wanghe)
Fk:loadTranslationTable{
  ["steam__wanghe"] = "妄壑",
  [":steam__wanghe"] = "锁定技，当你造成或受到伤害后，你将手牌摸至唯一最多，然后你弃置X张牌或失去1点体力（X为你自上次有角色进入濒死状态后发动此技能的次数）。",
  ["@steam__wanghe"] = "妄壑",
  ["#steam__wanghe-discard"] = "妄壑：你需弃置 %arg 张牌，否则失去1点体力",

  ["$steam__wanghe1"] = "人生于世，富贵于浮云尔，唯愿留名千古。",
  ["$steam__wanghe2"] = "世间倥偬几十载，彼可为功名，我亦可为之。",
  ["$steam__wanghe3"] = "燕雀安知鸿鹄之志哉！",
  ["$steam__wanghe4"] = "蛇可吞象，我钟会亦可吞天食地！",
  ["$steam__wanghe5"] = "大争之世，英雄弄风云，吾辈空叹否？",
}

local steam__wending = fk.CreateTriggerSkill{
  name = "steam__wending",
  events = {fk.EventPhaseStart},
  anim_type = "control",
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(self) and target == player and player.phase == Player.Play and not player:isKongcheng() then
      return table.find(player.room.alive_players, function (p)
        return p ~= player and not p:isKongcheng()
      end) ~= nil
    end
  end,
  on_cost = function(self, event, target, player, data)
    local cards = player.room:askForCard(player, 1, 1, false, self.name, true, nil, "#steam__wending-card")
    if #cards > 0 then
      self.cost_data = {cards = cards}
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local my_cards = self.cost_data.cards
    player:showCards(my_cards)
    local card = Fk:getCardById(my_cards[1])
    local targets = table.filter(room.alive_players, function(p) return not p:isKongcheng() end)
    if #targets == 0 then return end
    room:doIndicate(player.id, table.map(targets, Util.IdMapper))
    local discussion = U.Discussion(player, targets, self.name, {fromCardId = my_cards[1]})
    if player.dead then return end
    if discussion.color == card:getColorString() then
      local get = {}
      for _, p in ipairs(targets) do
        if p ~= player and discussion.results[p.id] and discussion.results[p.id].toCards then
          table.insertTableIfNeed(get, table.filter(discussion.results[p.id].toCards, function (id)
            return table.contains(p:getCardIds("h"), id)
          end))
        end
      end
      if #get > 0 then
        room:obtainCard(player, get, false, fk.ReasonPrey, player.id, self.name)
      end
    else
      for _, p in ipairs(targets) do
        if p ~= player and not p.dead and discussion.results[p.id] and discussion.results[p.id].opinion ~= card:getColorString() then
          room:setPlayerMark(p, "@@steam__wending-turn", player.id)
        end
      end
    end
  end,

  refresh_events = {"fk.StartDiscussion"},
  can_refresh = function (self, event, target, player, data)
    return target == player and data.reason == self.name and data.extra_data and data.extra_data.fromCardId
  end,
  on_refresh = function (self, event, target, player, data)
    local id = data.extra_data.fromCardId
    data.results[player.id] = data.results[player.id] or {}
    data.results[player.id].toCards = {id}
    data.results[player.id].opinion = Fk:getCardById(id):getColorString()
  end,
}
local steam__wending_targetmod = fk.CreateTargetModSkill{
  name = "#steam__wending_targetmod",
  bypass_times = function (self, player, skill, scope, card, to)
    return card and player and to and to:getMark("@@steam__wending-turn") == player.id
  end,
}
steam__wending:addRelatedSkill(steam__wending_targetmod)

ifzhonghui:addSkill(steam__wending)

Fk:loadTranslationTable{
  ["steam__wending"] = "问鼎",
  [":steam__wending"] = "出牌阶段开始时，你可以展示一张手牌作为意见并令所有角色议事，若结果与你意见相同，则你获得所有意见牌，否则你本回合对异议者使用牌无次数限制。",
  ["#steam__wending-card"] = "问鼎：你可展示一张手牌作为意见并令所有角色议事",
  ["@@steam__wending-turn"] = "被问鼎",
  ["$steam__wending1"] = "我欲行夏禹旧事，为天下人。",
  ["$steam__wending2"] = "今长缨在手，欲问鼎九州。",
  ["$steam__wending3"] = "我欲问鼎天下，试问谁与争锋？",
  ["$steam__wending4"] = "今提三尺剑、开万里疆，九鼎不足为重！",
  ["$steam__wending5"] = "风水轮流转，轮到我钟某问鼎重几何了。",
}

local steam__jizun = fk.CreateTriggerSkill{
  name = "steam__jizun",
  events = {fk.AfterDying},
  anim_type = "control",
  frequency = Skill.Wake,
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and target == player and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  can_wake = function (self, event, target, player, data)
    return true
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if player.role ~= "lord" then
      if room:isGameMode("role_mode") then
        RUtil.becomeWild(player)
      end
      room:handleAddLoseSkills(player, "steam__zhier")
    else
      room:recover { num = player.maxHp - player.hp, skillName = self.name, who = player, recoverBy = player }
    end
  end,
}
ifzhonghui:addSkill(steam__jizun)

Fk:loadTranslationTable{
  ["steam__jizun"] = "极尊",
  [":steam__jizun"] = "觉醒技。当你脱离濒死状态后，若你的身份：不为“主公”，则你将身份改为“野心家”并获得〖执耳〗；为“主公”，你将体力回复至体力上限。",
  -- 仅身份场修改身份为“野心家”。
  ["$steam__jizun1"] = "历经风浪至此，会不可止步于龙门。",
  ["$steam__jizun2"] = "人生艰难，如逆水行舟，不欲进则必退。",
  ["$steam__jizun3"] = "王霸之志在胸，我岂池中之物？",
  ["$steam__jizun4"] = "钟门欲屹万年，当先居万人之上。",
}

local steam__zhier = fk.CreateTriggerSkill{
  name = "steam__zhier$",
  anim_type = "control",
  events = {"fk.DiscussionCardsDisplayed"},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.results[player.id] and
      #player.room.logic:getActualDamageEvents(1, function(e)
        local damage = e.data[1]
        return damage.from and damage.from == player and damage.to ~= player and data.results[damage.to.id]
      end, Player.HistoryGame) > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room

    local targets = {}
    player.room.logic:getActualDamageEvents(1, function(e)
      local damageData = e.data[1]
      local victimId = damageData.to.id
      if damageData.from == player and damageData.to ~= player and damageData.to:isAlive() and data.results[victimId]
        and data.results[victimId].opinion ~= data.results[player.id].opinion then
        data.results[victimId].opinion = data.results[player.id].opinion
        table.insert(targets, victimId)
      end
      return false
    end, Player.HistoryGame)
    room:doIndicate(player.id, targets)

    room:sendLog{
      type = "#LogChangeOpinion",
      to = targets,
      arg = data.results[player.id].opinion,
      toast = true,
    }
  end,
}
ifzhonghui:addSkill(steam__zhier)
Fk:loadTranslationTable{
  ["steam__zhier"] = "执耳",
  [":steam__zhier"] = "主公技。当你参与的议事展示意见时，你可以令所有受到过你的伤害的其他角色意见视为与你相同。",
  ["$steam__zhier1"] = "事在人为，王侯之封不在人，而在我！",
  ["$steam__zhier2"] = "汉鹿已失，魏牛犹在，吾欲执其耳。",
}

local wenyang2 = General(extension, "steam2__wenyang", "wu", 4)

local steam__chongjian = fk.CreateViewAsSkill{
  name = "steam__chongjian",
  pattern = "jink,duel",
  mute = true,
  prompt = "#steam__chongjian",
  interaction = function(self)
    local all_names = self.pattern:split(",")
    local names = U.getViewAsCardNames(Self, self.name, all_names)
    if #names > 0 then
      return U.CardNameBox {choices = names, all_choices = all_names}
    end
  end,
  card_filter = function (self, to_select, selected)
    if Self:getHandcardNum() > 1 then
      return #selected < Self:getHandcardNum() - 1 and table.contains(Self:getCardIds("h"), to_select) and
        not Self:prohibitDiscard(to_select)
    else
      return false
    end
  end,
  view_as = function(self, cards)
    if not self.interaction.data then return nil end
    if Self:getHandcardNum() > 1 then
      if #cards ~= Self:getHandcardNum() - 1 then return end
      self.cost_data = cards
    elseif Self:getHandcardNum() == 0 then
      if #cards > 0 then return end
      self.cost_data = nil
    end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    return card
  end,
  before_use = function (self, player, use)
    local room = player.room
    if use.card.is_damage_card then
      player:broadcastSkillInvoke(self.name, table.random({1, 2}))
      room:notifySkillInvoked(player, self.name, "offensive")
    else
      player:broadcastSkillInvoke(self.name, table.random({3, 4}))
      room:notifySkillInvoked(player, self.name, "defensive")
    end
    if self.cost_data then
      room:throwCard(self.cost_data, self.name, player, player)
    else
      player:drawCards(1, self.name)
    end
  end,
  enabled_at_play = function(self, player)
    return player:getHandcardNum() ~= 1
  end,
  enabled_at_response = function(self, player, response)
    return not response and player:getHandcardNum() ~= 1
  end,
}
wenyang2:addSkill(steam__chongjian)
Fk:loadTranslationTable{
  ["steam2__wenyang"] = "文鸯",
  ["#steam2__wenyang"] = "独骑破军",
  ["illustrator:steam2__wenyang"] = "M云涯",
  ["designer:steam2__wenyang"] = "从珂",

  ["steam__chongjian"] = "冲坚",
  [":steam__chongjian"] = "你可以将手牌调整至1，视为使用【闪】或【决斗】。",
  ["#steam__chongjian"] = "刃仇：将手牌调整至1，视为使用【闪】或【决斗】",
  ["$steam__chongjian1"] = "奋六钧之力，破九天重云！",
  ["$steam__chongjian2"] = "攻敌营垒，不留一隅之地！",
}

local wenyang = General(extension, "steam__wenyang", "wei", 5)

local quedi = fk.CreateViewAsSkill{
  name = "steam__quedi",
  anim_type = "offensive",
  pattern = "duel",
  prompt = "#steam__quedi",
  card_filter = function (self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeEquip
    and not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,
  view_as = function(self, cards)
    if #cards > 1 then return end
    local c = Fk:cloneCard("duel")
    c.skillName = self.name
    if #cards == 1 then
      c:addSubcard(cards[1])
    end
    return c
  end,
  before_use = function (self, player, use)
    if #use.card.subcards == 0 then
      player.room:loseHp(player, 1, self.name)
    end
  end,
  enabled_at_response = Util.FalseFunc,
}
wenyang:addSkill(quedi)

local choujue = fk.CreateTriggerSkill{
  name = "steam__choujue",
  anim_type = "drawcard",
  events = {fk.DrawNCards},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    data.n = player:getMark("@steam__choujue")
  end,

  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player, "@steam__choujue", 0)
  end,

  refresh_events = {fk.TurnEnd, fk.Damaged},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:addPlayerMark(player, "@steam__choujue", 1)
  end,
}
wenyang:addSkill(choujue)


--[[
local choujue = fk.CreateViewAsSkill{
  name = "steam__choujue",
  anim_type = "offensive",
  pattern = "duel",
  prompt = "#steam__choujue-benghuai",
  interaction = function(self)
    return UI.ComboBox { choices = {"loseHp", "loseMaxHp"} }
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    local c = Fk:cloneCard("duel")
    c.skillName = self.name
    return c
  end,
  before_use = function (self, player, use)
    local room = player.room
    use.extra_data = use.extra_data or {}
    use.extra_data.steam__choujue_yimie = player.id
    local choice = self.interaction.data
    if choice == "loseMaxHp" then
      room:changeMaxHp(player, -1)
    else
      room:loseHp(player, 1, self.name)
    end
  end,
  after_use = function (self, player, use)
    if player.dead then return end
    local room = player.room
    if room:askForSkillInvoke(player, self.name, nil, "#steam__choujue-yimieself") then
      local x = player.hp
      room:loseHp(player, x, self.name)
      if player.dead then return end
      room:recover{
        who = player,
        num = x - 1,
        skillName = "yimie"
      }
      if player.dead then return end
      local newUse = U.askForUseVirtualCard(room, player, "duel", nil, self.name, "#steam__choujue-pojunduel",
      false, true, true, true, nil, true)
      if not newUse then return end
      newUse.extra_data = newUse.extra_data or {}
      newUse.extra_data.steam__choujue_pojun = player.id
      room.logic:addTriggerSkill(Fk.skills["steam__pojun"])
      room.logic:addTriggerSkill(Fk.skills["#steam__pojun_delay"])--理论上来说，这个会自动加，但是不知道为毛不加
      room:useCard(newUse)
      if player.dead or player:isNude() or player.hp < 1 then return end
      if room:askForSkillInvoke(player, self.name, nil, "#steam__choujue-pojunself") then
        player:broadcastSkillInvoke("steam__pojun")
        local cards = room:askForCardsChosen(player, player, 1, player.hp, "he", self.name)
        player:addToPile("$steam__pojun", cards, false, self.name)
        if player.dead then return end
        newUse = U.askForUseVirtualCard(room, player, "duel", nil, self.name, "#steam__choujue-duoruiduel",
        false, true, true, true, nil, true)
        if not newUse then return end
        newUse.extra_data = newUse.extra_data or {}
        newUse.extra_data.steam__choujue_duorui = player.id
        room.logic:addTriggerSkill(Fk.skills["duorui"])
        room:useCard(newUse)
      end
    end
  end,
  enabled_at_play = function(self, player)
    return true
  end,
  enabled_at_response = Util.FalseFunc,
}

local choujue_yimie = fk.CreateTriggerSkill{
  name = "#steam__choujue_yimie",
  mute = true,
  events = {fk.DamageCaused, fk.Damage},
  can_trigger = function(self, event, target, player, data)
    if event == fk.DamageCaused then
      if target == player and not player.dead and data.to.hp > data.damage then
        local useEvent = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
        if useEvent then
          local use = useEvent.data[1]
          return (use.extra_data or {}).steam__choujue_yimie == player.id
        end
      end
    else
      return data.to == player and not player.dead and player:isWounded() and
      data.extra_data and data.extra_data.steam__choujue_yimie
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.DamageCaused then
      player:broadcastSkillInvoke("yimie")
      room:loseHp(player, 1, "yimie")
      local x = data.to.hp - data.damage
      if x > 0 then
        data.extra_data = data.extra_data or {}
        data.extra_data.steam__choujue_yimie = (data.extra_data.steam__choujue_yimie or 0) + x
        data.damage = data.to.hp
      end
    else
      room:recover{
        who = player,
        num = data.extra_data.steam__choujue_yimie,
        skillName = "yimie"
      }
    end
  end,
}
choujue:addRelatedSkill(choujue_yimie)
local choujue_duorui = fk.CreateTriggerSkill{
  name = "#steam__choujue_duorui",
  anim_type = "control",
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    if target == player and not player.dead and player:getMark("duorui_source") == 0 and
    #player:getAvailableEquipSlots() > 0 and data.to ~= player and not data.to.dead then
      local useEvent = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      if useEvent then
        local use = useEvent.data[1]
        return (use.extra_data or {}).steam__choujue_duorui == player.id
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, _, player, data)
    local room = player.room
    player:broadcastSkillInvoke("duorui")
    local all_choices = {"WeaponSlot", "ArmorSlot", "DefensiveRideSlot", "OffensiveRideSlot", "TreasureSlot"}
    local choices = {}
    for _, slot in ipairs(all_choices) do
      if #player:getAvailableEquipSlots(Util.convertSubtypeAndEquipSlot(slot)) > 0 then
        table.insert(choices, slot)
      end
    end
    if #choices == 0 then return false end
    local choice = room:askForChoice(player, choices, "duorui", "#duorui-choice::" .. data.to.id, false, all_choices)
    room:abortPlayerArea(player, choice)
    local target = data.to
    if player.dead or target.dead then return false end
    local skills = {}
    local ban_types = {Skill.Limited, Skill.Wake, Skill.Quest}
    for _, skill_name in ipairs(Fk.generals[target.general]:getSkillNameList()) do
      local skill = Fk.skills[skill_name]
      if not (skill.lordSkill or table.contains(ban_types, skill.frequency)) then
        table.insertIfNeed(skills, skill_name)
      end
    end
    if target.deputyGeneral and target.deputyGeneral ~= "" then
      for _, skill_name in ipairs(Fk.generals[target.deputyGeneral]:getSkillNameList()) do
        local skill = Fk.skills[skill_name]
        if not (skill.lordSkill or table.contains(ban_types, skill.frequency)) then
          table.insertIfNeed(skills, skill_name)
        end
      end
    end
    if #skills == 0 then return false end
    choice = room:askForChoice(player, skills, "duorui", "#duorui-skill::" .. data.to.id, true)
    room:addTableMark(target, "duorui_target", choice)
    room:setPlayerMark(target, "@duorui_target", choice)
    if player:hasSkill(choice, true) then return false end
    room:addTableMark(player, "duorui_source", {target.id, choice})
    room:setPlayerMark(player, "@duorui_source", choice)
    room:handleAddLoseSkills(player, choice, nil, true, true)
  end,
}
local duorui_invalidity = fk.CreateInvaliditySkill {
  name = "#steam__duorui_invalidity",
  invalidity_func = function(self, from, skill)
    return table.contains(from:getTableMark("duorui_target"), skill.name)
  end
}
choujue:addRelatedSkill(choujue_duorui)
choujue:addRelatedSkill(duorui_invalidity)
wenyang:addSkill(choujue)

wenyang:addRelatedSkill("benghuai")
wenyang:addRelatedSkill("yimie")

-- 此为OL界破军，传导伤害也能+1
local steam__pojun = fk.CreateTriggerSkill{
  name = "steam__pojun",
  anim_type = "offensive",
  events = {fk.TargetSpecified, fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    local pojunCheck = function ()
      local useEvent = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
      if useEvent then
        local use = useEvent.data[1]
        return (use.extra_data or {}).steam__choujue_pojun == player.id
      end
      return false
    end
    if target == player and data.card and
    ((player:hasSkill(self) and data.card.trueName == "slash") or (data.card.name == "duel" and pojunCheck())) then
      if event == fk.TargetSpecified then
        local to = player.room:getPlayerById(data.to)
        return not to.dead and to.hp > 0 and not to:isNude()
      elseif event == fk.DamageCaused then
        return player:getHandcardNum() >= data.to:getHandcardNum() and
        #player:getCardIds(Player.Equip) >= #data.to:getCardIds(Player.Equip)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TargetSpecified then
      if (data.card.name == "duel") or player.room:askForSkillInvoke(player, self.name, nil, "#steam__pojun-invoke::"..data.to) then
        self.cost_data = {tos = {data.to}}
        return true
      end
    else
      self.cost_data = {tos = {data.to.id}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
      local to = room:getPlayerById(data.to)
      local cards = room:askForCardsChosen(player, to, 1, to.hp, "he", self.name)
      to:addToPile("$steam__pojun", cards, false, self.name)
    else
      data.damage = data.damage + 1
    end
  end,
}

local steam__pojun_delay = fk.CreateTriggerSkill{
  name = "#steam__pojun_delay",
  mute = true,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return #player:getPile("$steam__pojun") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:moveCardTo(player:getPile("$steam__pojun"), Player.Hand, player, fk.ReasonPrey, "steam__pojun")
  end,
}

steam__pojun:addRelatedSkill(steam__pojun_delay)
wenyang:addRelatedSkill(steam__pojun)

Fk:loadTranslationTable{
  ["steam__pojun"] = "破军",
  ["#steam__pojun_delay"] = "破军",
  [":steam__pojun"] = "①当你使用【杀】指定一个目标后，你可以将其至多X张牌扣置于该角色的武将牌旁（X为其体力值）；若如此做，当前回合结束时，该角色获得这些牌。②当你使用【杀】对手牌数与装备区里的牌数均不大于你的角色造成伤害时，此伤害+1。",

  ["#steam__pojun-invoke"] = "破军：你可以扣置 %dest 至多其体力值张牌直到回合结束",
  ["$steam__pojun"] = "破军",

  ["$steam__pojun1"] = "犯大吴疆土者，盛必击而破之！",
  ["$steam__pojun2"] = "若敢来犯，必叫你大败而归！",
}

wenyang:addRelatedSkill("duorui")

local steam__beishui = fk.CreateTriggerSkill{
  name = "steam__beishui",
  events = {fk.EnterDying},
  anim_type = "defensive",
  frequency = Skill.Limited,
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and target == player
    and player:hasSkill(choujue, true) and not player:isFakeSkill(choujue)
    and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:handleAddLoseSkills(player, "-steam__choujue|benghuai|yimie|steam__pojun|duorui")
    if player.dead then return end
    room:recover { num = player.maxHp - player.hp, skillName = self.name, who = player, recoverBy = player }
  end,
}
wenyang:addSkill(steam__beishui)
--]]

Fk:loadTranslationTable{
  ["steam__wenyang"] = "文鸯",
  ["#steam__wenyang"] = "",
  ["cv:steam__wenyang"] = "",
  ["designer:steam__wenyang"] = "从珂",
  ["illustrator:steam__wenyang"] = "",


  ["steam__quedi"] = "却敌",
  [":steam__quedi"] = "出牌阶段，你可以失去1点体力或将一张装备牌当【决斗】使用。",
  ["#steam__quedi"] = "却敌：失去1点体力或将一张装备牌当【决斗】使用",

  ["steam__choujue"] = "仇决",
  [":steam__choujue"] = "你的摸牌阶段摸牌数为0；回合结束时或受到伤害后，此数字+1。",
  ["@steam__choujue"] = "仇决",

  ["$steam__quedi1"] = "乐嘉风起残云散，万钧雷震万千军！",
  ["$steam__quedi2"] = "进袭如惊涛，破围如落潮！",
  --[[
  ["steam__choujue"] = "仇决",
  [":steam__choujue"] = "出牌阶段，你可以“崩坏”以视为使用一张附魔“夷灭”的【决斗】，你可以再“夷灭”自己以视为使用附魔“破军”的【决斗】，你可以再“破军”自己以视为使用附魔“夺锐”的【决斗】。",
  ["#steam__choujue-benghuai"] = "仇决：你可以“崩坏”以视为使用一张附魔“夷灭”的【决斗】",
  ["#steam__choujue-yimieself"] = "仇决：你可以“夷灭”自己，视为使用附魔“破军”的【决斗】",
  ["#steam__choujue-pojunduel"] = "仇决：请视为使用一张附魔“破军”的【决斗】",
  ["#steam__choujue-pojunself"] = "仇决：你可以“破军”自己，视为使用附魔“夺锐”的【决斗】",
  ["#steam__choujue-duoruiduel"] = "仇决：请视为使用一张附魔“夺锐”的【决斗】",
  ["#steam__choujue_duorui"] = "夺锐",
  ["#steam__choujue_yimie"] = "夷灭",

  ["steam__beishui"] = "背水",
  [":steam__beishui"] = "限定技，当你进入濒死状态时，可以失去“仇决”，然后获得“仇决”中提到的所有技能并回复体力至上限。",

  ["$steam__beishui1"] = "",
  ["$steam__beishui2"] = "",
  --]]
}


local wenyang3 = General(extension, "steam3__wenyang", "jin", 4)
Fk:loadTranslationTable{
  ["steam3__wenyang"] = "文鸯",
  ["#steam3__wenyang"] = "",
  ["cv:steam3__wenyang"] = "",
  ["designer:steam3__wenyang"] = "从珂",
  ["illustrator:steam3__wenyang"] = "鬼画府",
  ["~steam3__wenyang"] = "",
}
local chuifeng = fk.CreateViewAsSkill{
  name = "steam__chuifeng",
  anim_type = "offensive",
  prompt = "#steam__chuifeng",
  pattern = "slash",
  card_filter = function(self, to_select, selected)
    return #selected < 3 and table.contains(Self.player_cards[Player.Hand], to_select)
  end,
  view_as = function(self, cards)
    if #cards ~= 3 and not (#cards == 1 and Self:getHandcardNum() == 1) then return nil end
    local c = Fk:cloneCard("slash")
    c.skillName = self.name
    c:addSubcards(cards)
    return c
  end,
  after_use = function (self, player, use)
    local room = player.room
    if player.dead or not use.damageDealt then return end
    player:drawCards(3, self.name)
    if player.dead then return end
    local num = (player:getHandcardNum() + 1) // 2
    room:askForDiscard(player, num, num, false, self.name, false)
  end,
  enabled_at_play = function(self, player)
    return true
  end,
  enabled_at_response = function (self, player, response)
    return not response and not player:isKongcheng()
  end,
}
local chuifengBuff = fk.CreateTriggerSkill{
  name = "#steam__chuifeng_trigger",
  refresh_events = {fk.TargetSpecified},
  can_refresh = function (self, event, target, player, data)
    return player.id == data.to and table.contains(data.card.skillNames, chuifeng.name) and not player.dead
  end,
  on_refresh = function (self, event, target, player, data)
    player:addQinggangTag(data)
  end
}
chuifeng:addRelatedSkill(chuifengBuff)
wenyang3:addSkill(chuifeng)
Fk:loadTranslationTable{
  ["steam__chuifeng"] = "椎锋",
  [":steam__chuifeng"] = "你可以将三张或唯一一张手牌当无视防具的【杀】使用，若造成伤害，你摸三张牌并弃置半数向上手牌。",
  ["#steam__chuifeng"] = "椎锋：将三张或唯一一张手牌当无视防具的【杀】使用，若造成伤害，则摸3弃半",
  
  ["$steam__chuifeng1"] = "率军冲锋，不惧刀枪所阻！",
  ["$steam__chuifeng2"] = "登锋履刃，何妨马革裹尸！",
}

local lvdai = General(extension, "steam__lvdai", "wu", 4)
local yanke_skill = fk.CreateActiveSkill{
  name = "steam__yanke_skill",
  target_num = 1,
  mod_target_filter = Util.TrueFunc,
  target_filter = Util.TrueFunc,
  on_effect = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.to)
    room:damage({
      from = from,
      to = to,
      card = effect.card,
      damage = 1,
      skillName = effect.card.name.."_skill",
    })
  end,
}
yanke_skill.cardSkill = true
Fk:addSkill(yanke_skill)
local yanke = fk.CreateTriggerSkill{
  name = "steam__yanke",
  anim_type = "offensive",
  events = {fk.PreCardEffect},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and not data.card:isVirtual() and data.to
  end,
  on_cost = function (self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name, nil, "#steam__yanke-invoke::"..data.to..":"..data.card:toLogString()) then
      self.cost_data = {tos = {data.to}}
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local card = data.card:clone()
    local c = table.simpleClone(data.card)
    for k, v in pairs(c) do
      card[k] = v
    end
    card.skill = yanke_skill
    data.card = card
  end,
}
lvdai:addSkill(yanke)
Fk:loadTranslationTable{
  ["steam__lvdai"] = "吕岱",
  ["#steam__lvdai"] = "南宣国化",
  ["illustrator:steam__lvdai"] = "学徒小李",
  ["designer:steam__lvdai"] = "志文",

  ["steam__yanke"] = "严恪",
  [":steam__yanke"] = "你的非转化牌对一名角色生效前，你可将此牌效果改为造成1点伤害。",
  ["#steam__yanke-invoke"] = "严恪：你使用的%arg即将对 %dest 生效，是否将效果改为对其造成1点伤害？",

  ["$steam__yanke1"] = "为国勤事，体素精勤。",
  ["$steam__yanke2"] = "忠勤为国，通达治体。",
  ["~steam__lvdai"] = "再也不能，为吴国奉身了。",
}

local jiangwei = General(extension, "steam__jiangwei", "han", 4)
local qingbei = fk.CreateTriggerSkill{
  name = "steam__qingbei",
  anim_type = "special",
  events = {fk.EventPhaseChanging},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and table.contains({3, 4, 6}, data.to)
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#steam__qingbei"..data.to.."-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addTableMark(player, self.name, data.to)
    if data.to == 3 then
      room:addTableMark(player, "@steam__qingbei", "判")
      if not player.chained then
        player:setChainState(true)
      end
    elseif data.to == 4 then
      room:addTableMark(player, "@steam__qingbei", "摸")
      player:drawCards(6, self.name)
    elseif data.to == 6 then
      room:addTableMark(player, "@steam__qingbei", "弃")
      if not player:isKongcheng() then
        DIY.ShowCards(player, player:getCardIds("h"))
      end
    end
    data.to = Player.Play
  end,

  refresh_events = {fk.EventPhaseChanging, fk.Deathed},
  can_refresh = function(self, event, target, player, data)
    if event == fk.EventPhaseChanging then
      return target == player and table.contains(player:getTableMark(self.name), data.to)
    elseif event == fk.Deathed then
      return player:getMark(self.name) ~= 0 and data.damage and data.damage.from and data.damage.from == player
    end
  end,
  on_refresh = function(self, event, target, player, data)
    if event == fk.EventPhaseChanging then
      data.to = Player.Play
    elseif event == fk.Deathed then
      local room = player.room
      room:setPlayerMark(player, self.name, 0)
      room:setPlayerMark(player, "@steam__qingbei", 0)
    end
  end,
}
local ranji = fk.CreateTriggerSkill{
  name = "steam__ranji",
  anim_type = "drawcard",
  events = {fk.HpChanged, fk.MaxHpChanged, fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:getHandcardNum() < player.hp then
      if event == fk.AfterCardsMove then
        for _, move in ipairs(data) do
          if move.from == player.id then
            for _, info in ipairs(move.moveInfo) do
              if info.fromArea == Card.PlayerHand then
                return true
              end
            end
          end
        end
      else
        return target == player
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.phase == Player.Play or player.room:askForSkillInvoke(player, self.name, nil, "#steam__ranji-invoke")
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(2, self.name)
    if not player.dead then
      player.room:loseHp(player, 1, self.name)
    end
  end,
}
jiangwei:addSkill(qingbei)
jiangwei:addSkill(ranji)
Fk:loadTranslationTable{
  ["steam__jiangwei"] = "姜维",
  ["#steam__jiangwei"] = "护国麒麟",
  ["illustrator:steam__jiangwei"] = "depp",
  ["designer:steam__jiangwei"] = "志文",

  ["steam__qingbei"] = "倾北",
  [":steam__qingbei"] = "你的一个主要阶段开始前，你可以将之永久改为出牌阶段，若为判定/摸牌/弃牌阶段，你横置/摸六张牌/明置所有牌。"..
  "你杀死一名角色后，复原所有因此法改变的阶段。",
  ["steam__ranji"] = "燃己",
  [":steam__ranji"] = "你的手牌数低于体力值后，你可以摸两张牌，然后失去1点体力。若在你的出牌阶段，则此技能必须发动。",
  ["#steam__qingbei3-invoke"] = "倾北：即将开始判定阶段，是否永久改为出牌阶段并横置武将牌？",
  ["#steam__qingbei4-invoke"] = "倾北：即将开始摸牌阶段，是否永久改为出牌阶段并摸八张牌？",
  ["#steam__qingbei6-invoke"] = "倾北：即将开始弃牌阶段，是否永久改为出牌阶段并明置所有手牌？",
  ["@steam__qingbei"] = "倾北",
  ["#steam__ranji-invoke"] = "燃己：是否失去1点体力，摸两张牌？",

  ["$steam__qingbei1"] = "效逐日之夸父，怀忠志而长存。",
  ["$steam__qingbei2"] = "知天命而不顺，履穷途而强为。",
  ["$steam__ranji1"] = "此身为薪，炬成灰亦照大汉长明。",
  ["$steam__ranji2"] = "维之一腔骨血，可驱驰来北马否？",
  ["~steam__jiangwei"] = "姜维，姜维，又将何为？",
}

local guohuai = General(extension, "steam__guohuai", "wei", 4)
local shejing = fk.CreateTriggerSkill {
  name = "steam__shejing",
  events = {fk.EventPhaseChanging},
  can_trigger = function (self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.to > 2 and data.to < 7 and
      player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and #player.room:getOtherPlayers(player) > 0 then
      local turn_event = player.room.logic:getCurrentEvent():findParent(GameEvent.Turn, true)
      return turn_event ~= nil and turn_event.data[1] == player
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local to = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1,
      "#steam__shejing-choose:::"..U.ConvertPhse(data.to)..":"..U.ConvertPhse(data.to + 1), self.name, true)
    if #to > 0 then
      self.cost_data = {tos = to}
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if data.to == Player.Discard and not player:isKongcheng() then
      player:showCards(player:getCardIds("h"))
      if not player.dead then
        local cards = table.filter(player:getCardIds("h"), function (id)
          return Fk:getCardById(id).is_damage_card
        end)
        if #cards > 0 then
          room:recastCard(cards, player, self.name)
        end
      end
    end
    local p = room:getPlayerById(self.cost_data.tos[1])
    if not p.dead then
      room.logic:getCurrentEvent():addCleaner(function()
        p:gainAnExtraPhase(data.to + 1, true)
      end)
    end
    return true
  end,
}
guohuai:addSkill(shejing)
Fk:loadTranslationTable{
  ["steam__guohuai"] = "郭淮",
  ["#steam__guohuai"] = "云程烟凉",
  ["designer:steam__guohuai"] = "志文",
  ["illustrator:steam__guohuai"] = "心中一凛",

  ["steam__shejing"] = "摄境",
  [":steam__shejing"] = "你的回合内限一次，你的一个主要阶段开始时，你可以跳过之，令一名其他角色执行一个该阶段的下一阶段。若为弃牌阶段，"..
  "你须展示手牌并重铸其中所有伤害类牌。",
  ["#steam__shejing-choose"] = "摄境：是否跳过%arg，令一名角色执行%arg2？",

  ["$steam__shejing1"] = "北原乃敌我必争之地，宜先据之。",
  ["$steam__shejing2"] = "此乃明攻西围，暗袭阳遂之策也。",
  ["~steam__guohuai"] = "万策俱全，却没料到这步……",
}

local xinqiji = General(extension, "steam__xinqiji", "song", 3)
local kanshishou = fk.CreateTriggerSkill{
  name = "steam__kanshishou",
  anim_type = "special",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and (player.phase == Player.Start or player.phase == Player.Finish) and
      table.find(U.getUniversalCards(player.room, "t"), function (id)
        return not table.contains(player:getTableMark("@$steam__kanshishou"), Fk:getCardById(id).name)
      end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cards = table.filter(U.getUniversalCards(player.room, "t"), function (id)
      return not table.contains(player:getTableMark("@$steam__kanshishou"), Fk:getCardById(id).name)
    end)
    local use = U.askForUseRealCard(room, player, cards, nil, self.name, "#steam__kanshishou-ask",
      {expand_pile = cards}, true, true)
    if use then
      self.cost_data = use
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = Fk:cloneCard(self.cost_data.card.name)
    card.skillName = self.name
    room:addTableMark(player, "@$steam__kanshishou", card.name)
    local use = {
      card = card,
      from = player.id,
      tos = self.cost_data.tos,
    }
    room:useCard(use)
    if not use.damageDealt and not player.dead then
      room:addTableMark(player, self.name, card.name)
    end
  end,
}
local kanshishou_filter = fk.CreateFilterSkill{
  name = "#steam__kanshishou_filter",
  card_filter = function(self, to_select, player)
    return table.contains(player:getTableMark("steam__kanshishou"), to_select.name) and
      table.contains(player:getCardIds("h"), to_select.id)
  end,
  view_as = function(self, to_select)
    local card = Fk:cloneCard("slash", to_select.suit, to_select.number)
    card.skillName = "steam__kanshishou"
    return card
  end,
}
local butianlie = fk.CreateActiveSkill{
  name = "steam__butianlie",
  anim_type = "offensive",
  card_num = 0,
  target_num = 0,
  prompt = "#steam__butianlie",
  frequency = Skill.Limited,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and
      #player:getTableMark("@$steam__kanshishou") > 0
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local cards = table.filter(U.getUniversalCards(player.room, "t"), function (id)
      return table.contains(player:getTableMark("@$steam__kanshishou"), Fk:getCardById(id).name)
    end)
    room:setPlayerMark(player, "@$steam__kanshishou", 0)
    room:setPlayerMark(player, "steam__kanshishou", 0)
    while #cards > 0 and not player.dead do
      local use = U.askForUseRealCard(room, player, cards, nil, self.name, "#steam__butianlie-ask",
        {expand_pile = cards}, false, false)
      if use then
        local card = Fk:cloneCard(use.card.name)
        card.skillName = self.name
        table.removeOne(cards, use.card.id)
        use = {
          card = card,
          from = player.id,
          tos = use.tos,
        }
        if use.damageDealt and not player.dead then
          room:addTableMark(player, self.name, card.name)
        end
      end
    end
  end,
}
local butianlie_filter = fk.CreateFilterSkill{
  name = "#steam__butianlie_filter",
  card_filter = function(self, to_select, player)
    return table.contains(player:getTableMark("steam__butianlie"), to_select.name) and
      table.contains(player:getCardIds("h"), to_select.id)
  end,
  view_as = function(self, to_select)
    local card = Fk:cloneCard("analeptic", to_select.suit, to_select.number)
    card.skillName = "steam__butianlie"
    return card
  end,
}
kanshishou:addRelatedSkill(kanshishou_filter)
butianlie:addRelatedSkill(butianlie_filter)
xinqiji:addSkill(kanshishou)
xinqiji:addSkill(butianlie)
Fk:loadTranslationTable{
  ["steam__xinqiji"] = "辛弃疾",
  ["#steam__xinqiji"] = "匣中剑鸣",
  ["illustrator:steam__xinqiji"] = "",
  ["designer:steam__xinqiji"] = "续约",

  ["steam__kanshishou"] = "看试手",
  [":steam__kanshishou"] = "准备阶段或结束阶段，你可以视为使用一张未以此法使用过的普通锦囊牌，若未造成伤害，本局游戏你的此锦囊牌"..
  "视为【杀】。",
  ["steam__butianlie"] = "补天裂",
  [":steam__butianlie"] = "限定技，出牌阶段，你可以重置〖看试手〗的记录，并依次视为使用以此法恢复的普通锦囊牌，若造成伤害，"..
  "本局游戏你的此锦囊牌视为【酒】。",
  ["@$steam__kanshishou"] = "看试手",
  ["#steam__kanshishou-ask"] = "看试手：你可以视为使用其中一张牌",
  ["#steam__kanshishou_filter"] = "看试手",
  ["#steam__butianlie"] = "补天裂：是否重置并视为使用“看试手”记录的锦囊牌？",
  ["#steam__butianlie-ask"] = "补天裂：请视为使用其中一张牌",
  ["#steam__butianlie_filter"] = "补天裂",
}

local lvmeng = General(extension, "steam__lvmeng", "wu", 4)
lvmeng.hidden = true
local keji = fk.CreateTriggerSkill{
  name = "steam__keji",
  anim_type = "drawcard",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and not player:isKongcheng() then
      local room = player.room
      if #room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function (e)
        for _, move in ipairs(e.data) do
          if move.from == player.id then
            for _, info in ipairs(move.moveInfo) do
              if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                return true
              end
            end
          end
        end
      end, Player.HistoryTurn) > 0 then
        local cards = {}
        room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function (e)
          for _, move in ipairs(e.data) do
            if move.toArea == Card.DiscardPile then
              for _, info in ipairs(move.moveInfo) do
                if table.contains(room.discard_pile, info.cardId) then
                  table.insertIfNeed(cards, info.cardId)
                end
              end
            end
          end
        end, Player.HistoryTurn)
        if #cards > 0 then
          self.cost_data = {cards = cards}
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:moveCards({
      from = player.id,
      ids = player:getCardIds("h"),
      toArea = Card.DiscardPile,
      moveReason = fk.ReasonExchange,
      skillName = self.name,
      proposer = player.id,
      moveVisible = true,
    },
    {
      to = player.id,
      ids = self.cost_data.cards,
      toArea = Card.PlayerHand,
      moveReason = fk.ReasonExchange,
      skillName = self.name,
      proposer = player.id,
      moveVisible = true,
    })
  end,
}
lvmeng:addSkill(keji)
Fk:loadTranslationTable{
  ["steam__lvmeng"] = "吕蒙",
  ["#steam__lvmeng"] = "白衣渡江",
  ["illustrator:steam__lvmeng"] = "biou09",
  ["designer:steam__lvmeng"] = "云雀",

  ["steam__keji"] = "克己",
  [":steam__keji"] = "你失去过牌的回合结束时，你可以用你的所有手牌交换本回合进入弃牌堆的牌。",

  ["$steam__keji1"] = "隐忍克己，以待天时。",
  ["$steam__keji2"] = "一介武夫，终成一代儒将。",
  ["~steam__lvmeng"] = "咳咳……本想攻其不备，谁知……",
}

return extension
